#!/usr/bin/perl # update-mailstats.pl # # Copyright Craig Sanders 1999 # # this script is licensed under the terms of the GNU GPL. # # Pro rychlost je vhodne soubory /tmp/mailstat.old a /tmp/stats.db # umistit do ramky. Proto je dobre zmenit cesty k souborum a vytvorit # adresar /tmp/mrtg. Ten primontovat radkem v /etc/fstab. Neboli # mount -t tmpfs -o size=20m tmpfs /tmp/mrtg # tmpfs /tmp/mrtg tmpfs size=20m 0 0 use DB_File; use File::Tail ; $debug = 0; $mail_log = '/var/log/maillog' ; $stats_file = '/tmp/mrtg/stats.db' ; $db = tie(%stats, "DB_File", "$stats_file", O_CREAT|O_RDWR, 0666, $DB_HASH) || die ("Cannot open $stats_file"); #my $logref=tie(*LOG,"File::Tail",(name=>$mail_log,tail=>-1,debug=>$debug)); my $logref=tie(*LOG,"File::Tail",(name=>$mail_log,debug=>$debug)); while () { if (/ACCESS-CLIENT/) { $stats{"SPAM:spam"} += 1; #print "$stats{SPAM:spam}..." ; $db->sync; } if (/(status=sent|Passed SPAM)/) { if (/(discard|spam|SPAM)/) { $stats{"SPAM:spam"} += 1; #print "$stats{SPAM:spam}..." ; $db->sync; } ; next unless (/ postfix\//) ; # if (!/ postfix\//) { next; } # count sent messages if (/relay=([^,]+)/o) { $relay = $1 ; #print "$relay..." ; } ; if ($relay !~ /\[/o) { $stats{"SENT:$relay"} += 1; #print "$relay\n" ; $db->sync; } else { if ($relay ne "127.0.0.1[127.0.0.1]:10024") { $stats{"SENT:smtp"} +=1 ; #print "smtp\n" ; $db->sync; } } ; } elsif (/smtpd.*client=([^ ]+)/) { $client = $1; if ($client ne "localhost[127.0.0.1]") { # count received smtp messages $stats{"RECEIVED:smtp"} += 1; $db->sync ; } } elsif (/pickup.*(sender|uid)=/) { # count received local messages $stats{"RECEIVED:local"} += 1; $db->sync ; } ; } ; untie $logref ; untie %stats;