home *** CD-ROM | disk | FTP | other *** search
- Program Email_Alerter;
-
- {
- SMTP mail alerter. Alerts by email when alertable hosts state changed.
- Uses simple open source console SMTP mailer QMAILER.EXE by Shilonosov.A.
-
- User defined constants:
- SMTPSERV - name or IP address of an SMTP server for outgoing messages
- FROMADDR - email address from wich messages will be sent
- TOADDR - target email address
- SUBJ - subject of email message
- UPDATESECOND - update interval in seconds
- MAXTRIES - how many times try to send message if error, -1 - unlimited
- }
-
- const SMTPSERV='smtp.mailserver.com';
- const FROMADDR='from_netview@mailserver.com';
- const TOADDR= 'to_admin@mailserver.com';
- const SUBJ= 'NetView alert';
- const UPDATESECOND=10;
- const MAXTRIES=-1;
-
-
- var hst:tnvhost;
- v,v1,v2:integer;
- msgstr:string;
- dtm:TDateTime;
- tries:integer;
-
- function sendemail(msg:string):boolean;
- var s:string;
- begin
- s:='"'+smtpserv+'" "'+fromaddr+'" "'+toaddr+'" "'+subj+'"'+' "'+msg+'"';
- if(exec(nv_directory+'qmailer.exe',s,128)=1)then begin tries:=0;result:=true;end
- else begin
- if(maxtries=-1)then result:=false
- else begin
- if tries<maxtries then begin tries:=tries+1;result:=false;end
- else begin tries:=0;result:=true;end;
- end;
-
- end;
- end;
-
-
- begin
-
- hst:=tnvhost.create;
- msgstr:='';tries:=0;
- settimer(updatesecond*1000);
- repeat
- v:=waitevent(v1,v2);
- if(v=NMNP_ALERT)and((v1 and NVALERT_ALARMHOST)<>0)then
- begin
- hst.gethost(v2,0);
- if(hst.id<>0)then
- begin
- dtm:=Now;
-
- if(v1 and NVALERTMASK_HOSTUP)<>0 then
- begin
- msgstr:=msgstr+'<'+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+'> '+hst.hname+' online'+chr(13)+chr(10);
- end else
- if(v1 and NVALERTMASK_HOSTDOWN)<>0 then
- msgstr:=msgstr+'<'+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+'> '+hst.hname+' offline'+chr(13)+chr(10);
- end;
- end else
- if(v=8) and(msgstr<>'')then
- begin
- if sendemail(msgstr) then msgstr:='';
- end;
- until v=0;
- settimer(0);
- hst.free;
- end.
-