Ken Schweigert
Fri, 15 Feb 2008 13:18:50 -0800
As a small contribution to the project that has saved me and my users from thousands of spam messages, I would like to offer a simple perl script that I wrote that does some simple calculations. I mainly wrote it to see how effective Spamdyke was, what kind of errors spammers were getting, and how much spam actually hit my secondary MX server. I hope someone out there finds it useful, or at least interesting. As with most contributed code, I do not take any responsibility for (mis)use of my code. I'm still learning perl so there may be errors, so please review the code before executing it on your system. It works in my situation and gives me the results I was looking for so hopefully it will do the same for you.
Output:
[EMAIL PROTECTED] root]# cat /var/log/qmail/smtpd/current |
/usr/local/etc/spam-statistics.pl
3775 DENIED_RBL_MATCH
3294 DENIED_RDNS_MISSING
1780 DENIED_RDNS_RESOLVE
932 DENIED_IP_IN_RDNS
425 ALLOWED
124 DENIED_SENDER_NO_MX
25 TIMEOUT
23 DENIED_OTHER
12 ERROR:
3 DENIED_EARLYTALKER
Allowed: 425
Denied : 9968
% Spam : 95.91%
[EMAIL PROTECTED] root]#
Code:
[EMAIL PROTECTED] root]# more /usr/local/etc/spam-statistics.pl
#!/usr/bin/perl -w
use diagnostics;
use strict;
# Usage: # cat /var/log/qmail/smtpd/current | ./this_file
my %status = (); # hash of status connections
my ($allow,$deny,$spampercentage);
while(<>){
my $line = $_;
if( /[A-Z].{5,5}/ ){
my ($timestamp,$sdstatus) = split(/\s/ , $line);
next if $sdstatus eq "CHKUSER";
$status{$sdstatus}++;
}
}
foreach my $stat (sort keys %status){
if( $stat =~ m/ALLOWED/){
$allow = $status{$stat};
}
else{
$deny += $status{$stat};
}
}
$spampercentage = sprintf("%.2f", ($deny/($allow+$deny)*100) );
foreach my $key (sort { $status{$b} <=> $status{$a} || $a cmp $b; }
keys %status){
print "$status{$key}\t$key\n";
}
print "\n";
print "Allowed: $allow \n";
print "Denied : $deny \n";
print "% Spam : $spampercentage% \n";
[EMAIL PROTECTED] root]#
Respectfully contributed,
ken schweigert
--
Have a nice day ... unless you've made other plans.
_______________________________________________
spamdyke-users mailing list
spamdyke-users@spamdyke.org
http://www.spamdyke.org/mailman/listinfo/spamdyke-users