smeserver-zabbix-agent/root/var/lib/zabbix/bin/util_parse_mail_in

119 lines
3.4 KiB
Perl

#!/usr/bin/perl -w
# Copyright (C) 2009-2016 Daniel Berteaud <daniel@firewall-services.com>
# 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 = (
dnsbl => qr{dnsbl\s+90},
rhsbl => qr{rhsbl\s+90},
uribl => qr{uribl\s+90},
clamav => qr{virus::clam(av|dscan)\s+90},
check_earlytalker => qr{(check_)?earlytalker\s+90},
check_basicheaders => qr{(check_basic)?headers\s+90},
check_goodrcptto => qr{(check_)?goodrcptto\s+90},
check_spamhelo => qr{(check_)?spamhelo\s+90},
fcrdns => qr{fcrdns\s+90},
karma => qr{karma\s+90},
spf => qr{sender_permitted_from\s+90},
tls_failed => qr{tls\s+90},
resolvable_fromhost => qr{(require_)?resolvable_fromhost}
);
my @others = qw(total_denied spam_denied other_denied spam_queued queued total);
my %cnt;
foreach (keys %denied, @others){
$cnt{$_} = 0;
}
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
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'
if ($line =~ m/msg denied before queued/){
$cnt{total_denied}++;
foreach (keys %denied){
if ($line =~ m/$denied{$_}/){
$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 (keys %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 (keys %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 (keys %denied, @others){
print "$_ ";
}
print "\n";
exit 1;
}
exit 0;