The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Simple mrtg graphing...
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);


Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org