home *** CD-ROM | disk | FTP | other *** search
- program StateLogger;
- {
- *****************************************************************************
- *Hosts state logger script v1.0 for NetView by Killer<R> *
- *User defined constants: *
- *SMARTMODE- if 1 then logs only those hosts wich state is changed after *
- * last logging. If 0 then logs all hosts *
- *LOGFILENAME- filename of log file without extension and number *
- *MAXFILESIZE- maximum size of log file in bytes *
- *RENAMEMODE- If 1 then rename logfile when too large. If 0 then log file *
- * will be truncated from the beggining *
- *****************************************************************************
- }
- const smartmode=0;
- const logfilename='recheck';
- const maxfilesize=1048576;
- const renamemode=0;
-
- var e,f,i1,i2,filecnt:integer;
- canlog:boolean;
- s1,s2:string;
- hst:tnvhost;
- dtm:TDateTime;
-
-
-
- function openlogfile:integer;
- var sz,szh,f:integer;
- s,fn:string;
- begin
- fn:=nv_directory+logfilename+inttostr(filecnt)+'.log';
- f:=openfile(fn,7);sz:=getfilesize(f,szh);
- if(sz>maxfilesize)then
- begin
- if renamemode<>0 then begin
- closefile(f);
- filecnt:=filecnt+1;
- writeini('StateLogger','LogFileCount',inttostr(filecnt));
- fn:=nv_directory+logfilename+inttostr(filecnt)+'.log';
- f:=openfile(fn,7);
- end else begin
- readfile(f,sz,s);
- if(length(s)>maxfilesize)then delete(s,1,maxfilesize-length(s));
- closefile(f);f:=openfile(fn,11);
- writefile(f,s);
- end;
- end;
- setfilepointer(f,0,0,2);
- result:=f;
- end;
-
- begin
- filecnt:=strtoint(readini('StateLogger','LogFileCount','0'));
- e:=0;hst:=tnvhost.create;
- f:=openlogfile;
- dtm:=Now;
- writefile(f,';-----------LOADED ON '+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+chr(13)+chr(10));
- closefile(f);
- setstatus('Idle');
- repeat
- e:=waitevent(i1,i2);
- if(e=NMNP_ACTION)then
- begin
- if(i1 and NVACTION_RECHECK)<>0 then
- begin
- if(i1 and NVACTION_LIST)<>0 then
- begin
- setstatus('Working');
- f:=openlogfile;
- dtm:=Now;
- writefile(f,';-----------RECHECK ON '+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+chr(13)+chr(10));
-
- hst.nextid:=0;
- repeat
- hst.gethost(hst.nextid,0);
- if(hst.id<>0)then
- begin
-
- canlog:=smartmode=0;
- s1:=hst.getmetavar('isonold');
- s2:=hst.getmetavar('ison');
- if(s1<>s2)then
- begin
- if not canlog then canlog:=true;
- hst.setmetavar('isonold',s2);
- end;
-
-
-
- if(canlog)then
- begin
- s1:='!'+hst.hname+chr(9)+hst.hip+chr(9)+hst.getmetavar('ctime')+chr(13)+chr(10);
- writefile(f,s1);
- end;
-
- end;
- until hst.nextid=0;
-
- writefile(f,';--------------------------------------------'+chr(13)+chr(10));
- closefile(f);
- setstatus('Idle');
- end;
- end;
- end;
- until e=0;
- f:=openlogfile;
- dtm:=Now;
- writefile(f,';-----------UNLOADED ON '+FormatDateTime('YYYY-MM-DD HH:MM.SS',dtm)+chr(13)+chr(10));
- closefile(f);
-
- hst.free;
- end.
-