Comment in en, and some code cleanup in util_parse_mail_in

This commit is contained in:
Daniel Berteaud 2016-04-19 15:21:04 +02:00
parent a6074b8ca2
commit 3514ca3349
1 changed files with 19 additions and 16 deletions

View File

@ -18,10 +18,13 @@
# along with Foobar; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# This script parse qpsmtpd logs (which must be sent to STDIN), and count the number
# of emails rejected by each plugins, and those accepted. You need to logterse plugin enabled
my $what = $ARGV[0] || '';
# On initialise nos compteurs a 0
# This is the list of plugins we can get stats for
# you can set the regex used to identify a line in the logs
my %denied = (
dnsbl => qr{dnsbl\s+90},
rhsbl => qr{rhsbl\s+90},
@ -47,14 +50,15 @@ foreach (keys %denied, @others){
while (<STDIN>) {
my $line = $_;
# on limites aux lignes concernant logterse
# @400000004994ad092afa867c 18386 logging::logterse plugin: etc...
# selon la version de qpsmtpd, les lignes logterse peuvent varier
# We only want logterse lines like
# @400000004994ad092afa867c 18386 logging::logterse plugin:
# The format can slightly change depending on qpsmtpd version
next unless $line =~ m/^\@[0-9a-f]{24} \d+( \((queue|deny)\))? logging::logterse/;
# D'abord on traite tout ceux qui contiennent 'msg denied before queued'
# Lets count all the message which have been denied 'msg denied before queued'
if ($line =~ m/msg denied before queued/){
$cnt{total_denied}++;
# Now try to find the plugin responsible for the deny
foreach (keys %denied){
if ($line =~ m/$denied{$_}/){
$cnt{$_}++;
@ -63,26 +67,27 @@ while (<STDIN>) {
next;
}
# Les messages refuses par spamassassin
# Rejected by spamassassin because spam score is too high
elsif ($line =~ m/spam score exceeded threshold/){
$cnt{spam_denied}++;
next;
}
# Spam mis en queue
elsif ($line =~ m/queued.*Yes/){
# Tagged as spam, but kept accepted
elsif ($line =~ m/queued\s+<.*>\s+Yes,\s+(score|hits)=/){
$cnt{spam_queued}++;
next;
}
# Enfin, les bon mails
elsif ($line =~ m/queued.*No/){
# Queued, not tagged as spam, those are the clean emails
elsif ($line =~ m/queued\s+<.*>\s+No,\s+(score|hits)=/){
$cnt{queued}++;
next;
}
}
# Caclul des totaux:
# Now lets count other_denied, which is total_denied minus
# all the known plugins denied
$cnt{other_denied} = $cnt{total_denied};
foreach (keys %denied){
$cnt{total} = $cnt{total} + $cnt{$_};
@ -92,21 +97,19 @@ foreach (@others){
$cnt{total} = $cnt{total} + $cnt{$_} if ($_ !~ /total/);
}
# Si l'argument est "print" on affiche toutes les stats
# The print argument prints all on stdout
if ($what eq "print"){
foreach (keys %denied,@others){
print "$_: $cnt{$_}\n";
}
}
# Si l'argument correspond a un compteur definit
# On affiche uniquemment cette valeur
# If the arg is a known plugin, prints only its value
elsif (defined $cnt{$what}){
print "$cnt{$what}\n";
}
# Sinon, on quitte avec une erreur
# Else, print an error
else{
print "supported items are: ";
foreach (keys %denied, @others){