2. The source code


#!D:\dev\perl 
# Log Agent version 1.0 (c)2000
# By Floydman
# [email protected]
# You can freely use and distribute this Perl program, and change the code to fit your purposes as well.
# If you feel that somehow you improve this program, please let me know so I can update the original.
# I guess you can consider this is Open Source software.

# Using Win32::AdvNotify 
# By Amine Moulay Ramdane 
# Website: http://www.generation.net/~aminer/Perl/ 
use Win32::AdvNotify qw(FILE_NAME SIZE INFINITE Yes No 
                        All %ActionName %ActionColor);

# @mondir contains the list of directories to be monitored
@mondir = ("D:/Program Files/Security/Grisoft/Avg6/Log/", 
	   "D:/Program Files/Utils/GetRight/Log/",
	   "D:/Winnt/Internet Logs/",
	   "D:/Program Files/Winetd/logs/");

# $mainlog contains the location of the master directory
$mainlog = '//darkside/log$/';

my $obj  = new Win32::AdvNotify()|| die "Can't create object\n";

# Note: you launch a thread for each directory you want to monitor,
# meaning one thread per object in @mondir  

print "Log Agent 1.0 by Floydman\n";

my $Thr1 = $obj->StartThread(Directory    => $mondir[0],  
                             Filter       =>  All ,
                             WatchSubtree =>  No ) || die "Can't start thread\n";

my $Thr2 = $obj->StartThread(Directory    => $mondir[1],  
                             Filter       =>  All , 
                             WatchSubtree =>  No ) || die "Can't start thread\n";

my $Thr3 = $obj->StartThread(Directory    => $mondir[2],  
                             Filter       =>  All , 
                             WatchSubtree =>  No ) || die "Can't start thread\n";

my $Thr4 = $obj->StartThread(Directory    => $mondir[3],  
                             Filter       =>  All , 
                             WatchSubtree =>  No ) || die "Can't start thread\n";

print "\nThreads started successfuly ...\n";

#DO NOT FORGET TO ENABLE EACH ONE OF YOUR THREADS
$Thr1->EnableWatch() || die "Problem starting EnableWatch()\n"; 
$Thr2->EnableWatch() || die "Problem starting EnableWatch()\n";
$Thr3->EnableWatch() || die "Problem starting EnableWatch()\n";
$Thr4->EnableWatch() || die "Problem starting EnableWatch()\n";

print "\nTo exit from the loop press [CTRL-C] ...\n\n";

while($Thr1->Wait(INFINITE))# exit with [Ctrl-C] signal 
{
 while($Thr1->Read(\@data))# exit when the list is empty
 {for($i=0;$i<=$#data;$i++)
  {$obj->TextColor($ActionColor{$data[$i]->{Action}});
   open (LOGFILE, $data[$i]->{Directory}.$data[$i]->{FileName}) or die "Can't open log file";
   flock (LOGFILE, 1) or die "Can't lock file";
   @Lines = ;
   open (MAINLOG, ">>".$mainlog.$data[$i]->{FileName}) or die "Can't open master log file";
   flock (MAINLOG, 2) or die "Can't lock file for writing";
   print MAINLOG $Lines[-1] or die "Can't read from file";
   close (MAINLOG) or die "Can't close master log file";
   close (LOGFILE) or die "Can't close file";

}}
}

# never forget to terminate your threads. 

$Thr1->Terminate(); # terminate thread1
$Thr2->Terminate(); # terminate thread2
$Thr3->Terminate(); # terminate thread3
$Thr4->Terminate(); # terminate thread4

# never forget to call the destructor

undef $obj;


1. About LogAgent
3. The experiment

Table of contents
Hosted by www.Geocities.ws

1