home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 April / CHIP_CD_2005-04.iso / software / netv / NVinst.exe / $INSTDIR / Scripts / Scripter / EmailAlert.nvs < prev    next >
Encoding:
Text File  |  2005-02-22  |  2.0 KB  |  76 lines

  1. Program Email_Alerter;
  2.  
  3. {
  4. SMTP mail alerter. Alerts by email when alertable hosts state changed.
  5. Uses simple open source console SMTP mailer QMAILER.EXE by Shilonosov.A.
  6.  
  7. User defined constants:
  8. SMTPSERV - name or IP address of an SMTP server for outgoing messages
  9. FROMADDR - email address from wich messages will be sent
  10. TOADDR   - target email address
  11. SUBJ     - subject of email message
  12. UPDATESECOND - update interval in seconds
  13. MAXTRIES     - how many times try to send message if error, -1 - unlimited
  14. }
  15.  
  16. const SMTPSERV='smtp.mailserver.com';
  17. const FROMADDR='from_netview@mailserver.com';
  18. const TOADDR=  'to_admin@mailserver.com';
  19. const SUBJ=    'NetView alert';
  20. const UPDATESECOND=10;
  21. const MAXTRIES=-1;
  22.  
  23.  
  24. var hst:tnvhost;
  25.     v,v1,v2:integer;
  26.     msgstr:string;
  27.     dtm:TDateTime;
  28.     tries:integer;
  29.  
  30. function sendemail(msg:string):boolean; 
  31. var s:string;
  32. begin
  33. s:='"'+smtpserv+'" "'+fromaddr+'" "'+toaddr+'" "'+subj+'"'+' "'+msg+'"';
  34. if(exec(nv_directory+'qmailer.exe',s,128)=1)then begin tries:=0;result:=true;end
  35.                    else begin
  36. if(maxtries=-1)then result:=false
  37.                else begin
  38.                     if tries<maxtries then begin tries:=tries+1;result:=false;end
  39.                                       else begin tries:=0;result:=true;end;
  40.                     end;
  41.  
  42. end;
  43. end;
  44.  
  45.  
  46. begin
  47.  
  48. hst:=tnvhost.create;
  49. msgstr:='';tries:=0;
  50. settimer(updatesecond*1000);
  51. repeat
  52. v:=waitevent(v1,v2);
  53. if(v=NMNP_ALERT)and((v1 and NVALERT_ALARMHOST)<>0)then
  54. begin
  55. hst.gethost(v2,0);
  56. if(hst.id<>0)then 
  57. begin
  58. dtm:=Now;
  59.  
  60. if(v1 and NVALERTMASK_HOSTUP)<>0 then
  61. begin
  62. msgstr:=msgstr+'<'+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+'> '+hst.hname+' online'+chr(13)+chr(10);
  63. end else
  64. if(v1 and NVALERTMASK_HOSTDOWN)<>0 then
  65. msgstr:=msgstr+'<'+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+'> '+hst.hname+' offline'+chr(13)+chr(10);
  66. end;
  67. end else
  68. if(v=8) and(msgstr<>'')then
  69. begin
  70. if sendemail(msgstr) then msgstr:='';
  71. end;
  72. until v=0;
  73. settimer(0);
  74. hst.free;
  75. end.
  76.