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

  1. program StateLogger;
  2. {
  3. *****************************************************************************
  4. *Hosts state logger script v1.0 for NetView by Killer<R>                    *
  5. *User defined constants:                                                    *
  6. *SMARTMODE-   if 1 then logs only those hosts wich state is changed after   *
  7. *             last logging. If 0 then logs all hosts                        *
  8. *LOGFILENAME- filename of log file without extension and number             *
  9. *MAXFILESIZE- maximum size of log file in bytes                             *
  10. *RENAMEMODE-  If 1 then rename logfile when too large. If 0 then log file   *
  11. *             will be truncated from the beggining                          *
  12. *****************************************************************************
  13. }
  14. const smartmode=0;
  15. const logfilename='recheck';
  16. const maxfilesize=1048576;
  17. const renamemode=0;
  18.  
  19. var e,f,i1,i2,filecnt:integer;
  20.     canlog:boolean;
  21.     s1,s2:string;
  22.     hst:tnvhost;
  23.     dtm:TDateTime;
  24.  
  25.  
  26.  
  27. function openlogfile:integer;
  28. var sz,szh,f:integer;
  29.     s,fn:string;
  30. begin
  31. fn:=nv_directory+logfilename+inttostr(filecnt)+'.log';
  32. f:=openfile(fn,7);sz:=getfilesize(f,szh);
  33. if(sz>maxfilesize)then
  34. begin
  35. if renamemode<>0 then begin
  36. closefile(f);
  37. filecnt:=filecnt+1;
  38. writeini('StateLogger','LogFileCount',inttostr(filecnt));
  39. fn:=nv_directory+logfilename+inttostr(filecnt)+'.log';
  40. f:=openfile(fn,7);
  41. end else begin
  42. readfile(f,sz,s);
  43. if(length(s)>maxfilesize)then delete(s,1,maxfilesize-length(s));
  44. closefile(f);f:=openfile(fn,11);
  45. writefile(f,s);
  46. end;
  47. end;
  48. setfilepointer(f,0,0,2);
  49. result:=f;
  50. end;
  51.  
  52. begin
  53. filecnt:=strtoint(readini('StateLogger','LogFileCount','0'));
  54. e:=0;hst:=tnvhost.create;
  55. f:=openlogfile;
  56. dtm:=Now;
  57. writefile(f,';-----------LOADED ON '+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+chr(13)+chr(10));
  58. closefile(f);
  59. setstatus('Idle');
  60. repeat
  61. e:=waitevent(i1,i2);
  62. if(e=NMNP_ACTION)then
  63. begin
  64. if(i1 and NVACTION_RECHECK)<>0 then
  65. begin
  66. if(i1 and NVACTION_LIST)<>0 then
  67. begin
  68. setstatus('Working');
  69. f:=openlogfile;
  70. dtm:=Now;
  71. writefile(f,';-----------RECHECK ON '+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+chr(13)+chr(10));
  72.  
  73. hst.nextid:=0;
  74. repeat
  75. hst.gethost(hst.nextid,0);
  76. if(hst.id<>0)then
  77. begin
  78.  
  79. canlog:=smartmode=0;
  80. s1:=hst.getmetavar('isonold');
  81. s2:=hst.getmetavar('ison');
  82. if(s1<>s2)then
  83. begin
  84. if not canlog then canlog:=true;
  85. hst.setmetavar('isonold',s2);
  86. end;
  87.  
  88.  
  89.  
  90. if(canlog)then
  91. begin
  92. s1:='!'+hst.hname+chr(9)+hst.hip+chr(9)+hst.getmetavar('ctime')+chr(13)+chr(10);
  93. writefile(f,s1);
  94. end;
  95.  
  96. end;
  97. until hst.nextid=0;
  98.  
  99. writefile(f,';--------------------------------------------'+chr(13)+chr(10));
  100. closefile(f);
  101. setstatus('Idle');
  102. end;
  103. end;
  104. end;
  105. until e=0;
  106. f:=openlogfile;
  107. dtm:=Now;
  108. writefile(f,';-----------UNLOADED ON '+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+chr(13)+chr(10));
  109. closefile(f);
  110.  
  111. hst.free;
  112. end.
  113.