spam_report.pl



NAME

spam_report.pl


DESCRIPTION

Debian Exim4 + Spamassassin spam stats report.


COPYRIGHT

Copyright 2010 Etienne LEMEE <coding AT etilem DOT net>

This piece of code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


#!/usr/bin/perl -w

use strict;

#  Safe mail
#   91612       /var/spool/sa-exim/SAnotspam
#   31600       /var/spool/sa-exim/SAspamaccept

#  Spam junk
#   167828      /var/spool/sa-exim/SAtempreject
#   262324      /var/spool/sa-exim/SApermreject
#   665344      /var/spool/sa-exim/SAdevnull

#  Put the following line in /etc/crontab for a 7 days quarantine daily purge at 6:35 AM
#  35 6 * * * root find /var/spool/sa-exim -type f -ctime +7 -exec rm -f '{}' \;

my  $dir = "/var/spool/sa-exim";
my  %stats = ();
my  ($spc, $sfc) = (0,0);
my  @spam = qw(
SAdevnull
SApermreject
SAtempreject
);
my  @safe = qw(
SAspamaccept
SAnotspam
);
my  $ack = "SAspamaccept";

for (qx"du -s $dir/SA*") {
    chomp;
    my ($rv, $lv) = split " ";
    $lv =~ s!.*/!!g;
    $stats{$lv} = $rv;
}

-e "$dir/$_" and $spc += $stats{$_} for (@spam);
-e "$dir/$_" and $sfc += $stats{$_} for (@safe);

my $total = ($spc + $sfc) / 100;

$stats{SPAM} = $spc ? sprintf "%0.2f", ($spc / $total) : 0;
$stats{SAFE} = $sfc ? sprintf "%0.2f", ($sfc / $total) : 0;
$stats{PASS} = $stats{$ack} ? sprintf "%0.2f", ($stats{$ack} / $total) : 0;

chomp($total = qx"cd $dir && du -sh|cut -f 1");

chomp(my $h = qx"hostname");

print << "EOL";

    Spam Report on $h

    spams rejected  : $stats{SPAM}%

    safe mails      : $stats{SAFE}% ($stats{PASS}% marked as spam)

    quarantine      : $total

EOL