#!/usr/bin/perl -w # Copyright (C) 2009 Daniel Berteaud # This file is part of smeserver-zabbix-agent package. # This script is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This script is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with Foobar; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA my $what = $ARGV[0] || ''; # On initialise nos compteurs a 0 my @denied = qw(dnsbl rhsbl clamav check_earlytalker check_basicheaders check_goodrcptto check_spamhelo); my @others = qw(total_denied spam_denied other_denied spam_queued queued total); my %cnt; foreach (@denied,@others){ $cnt{$_} = 0; } while () { my $line = $_; # on limites aux lignes concernant logterse # @400000004994ad092afa867c 18386 logging::logterse plugin: etc... next unless $line =~ m/^\@[0-9a-f]{24} \d+ logging::logterse plugin/; # D'abord on traite tout ceux qui contiennent 'msg denied before queued' if ($line =~ m/msg denied before queued/){ $cnt{total_denied}++; foreach (@denied){ if ($line =~ m/$_/){ $cnt{$_}++; } } next; } # Les messages refuses par spamassassin elsif ($line =~ m/spam score exceeded threshold/){ $cnt{spam_denied}++; next; } # Spam mis en queue elsif ($line =~ m/queued.*Yes/){ $cnt{spam_queued}++; next; } # Enfin, les bon mails elsif ($line =~ m/queued.*No/){ $cnt{queued}++; next; } } # Caclul des totaux: $cnt{other_denied} = $cnt{total_denied}; foreach (@denied){ $cnt{total} = $cnt{total} + $cnt{$_}; $cnt{other_denied} = $cnt{other_denied} - $cnt{$_}; } foreach (@others){ $cnt{total} = $cnt{total} + $cnt{$_} if ($_ !~ /total/); } # Si l'argument est "print" on affiche toutes les stats if ($what eq "print"){ foreach (@denied,@others){ print "$_: $cnt{$_}\n"; } } # Si l'argument correspond a un compteur definit # On affiche uniquemment cette valeur elsif (defined $cnt{$what}){ print "$cnt{$what}\n"; } # Sinon, on quitte avec une erreur else{ print "supported items are: "; foreach (@denied, @others){ print "$_ "; } print "\n"; exit 1; } exit 0;