#!/usr/bin/perl 
#
#  spam-stats.pl  -- scan logfile and retrieve spam stats messages,
#                    this version uses logtail to save time
#
# 7/30/03  by rpuhek@etnsystems.com
#

$statfile="/var/local/spam-stats/counts";
$offsetfile="/var/local/spam-stats/offset";
$logfile="/var/log/syslog";

$tail_cmd="/usr/sbin/logtail";

#open STATS, $statfile or die "ERROR: Unable to open $statfile $!\n";
dbmopen %stats, $statfile, 0666 or die "ERROR: Unable to open statsfile: $statfile $!\n";


open (LOG, "$tail_cmd $logfile $offsetfile|") or die "ERROR: Unable to open logfile: $logfile $!\n";

while (<LOG>) {
	$stats{spam}++	if /identified spam/;
	$stats{clean}++	if /clean message/;
	$stats{skipped}++	if /skipped large/;
	$stats{total}++		if /connection from/;
	$stats{processed}++	if /processing message/;
};

close LOG;


foreach $key (keys(%stats)) {
	print "$key: $stats{$key}\n";
};


$uptime = `uptime`;
$hostname = `hostname -f`;

chop $uptime;
chop $hostname;

$uptime =~ s/.*up //;
$uptime =~ s/,\s*?[0-9]* user.*//;

print "uptime: $uptime\nhostname: $hostname\n";

dbmclose %stats;


