Author: Erin
Date: 06-08-04 16:33
This is a perl script for graphing virus activity via email in mrtg. This is for the local machine only.
-------------------
#!/usr/bin/perl -w
use strict;
my @DATA;
my $virus = 0;
my $oldvirus = 0;
my $date = `/bin/date`;
my $logfile = "/var/log/maillog";
my $datafile = "/usr/home/users/mrtggraph/snmp-log/virus-mrtg.log";
($oldvirus) = getOldStats($datafile);
($virus) = getStats();
putStats($datafile, $virus);
sub getStats {
my $vir;
open(DATA, "$logfile") or die "Unable to open log file: $!";
while(<DATA>) {
if ( /VIRUS\:/ ) {
$vir++;
};
};
close(DATA);
return ($vir);
}
sub getOldStats {
my($filename) = @_;
open(OLD, $filename) || warn "$0: Unable to open $filename for reading";
my($line) = <OLD>;
close(OLD);
return ($line);
}
sub putStats {
my($filename, $vir) = @_;
open(STAT, ">$filename") || return "";
print STAT "$vir\n";
close(STAT);
return "1";
}
print $virus-$oldvirus . "\n";
print "0\n";
print "$date";
print "localhost\n";
exit(1);
|
|