1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#!@@PERL@@ -w
#
# Graphs statistics for e-mails passing through a MailScanner filter
#
# Usage: Link into /etc/munin/plugins/
#
# Requirements:
#
# The logtail command
#
# Parameters supported:
#
# config (required)
#
# Configurable variables:
#
# logfile - The file where MailScanner logs its action (default: /var/log/mail.log)
# logtail - The location of the logtail command (default: /usr/sbin/logtail)
# offsetfile - The location of the offset file (default: /tmp/lrrd-mailscanner.offset)
#
# Bugs:
#
# None known
#
# $Log$
# Revision 1.1.2.1 2005/02/16 19:52:32 toreanderson
# Use @@PLUGSTATE@@ as location for the state file, instead of the insecure
# /tmp.
#
# Revision 1.1 2004/12/09 20:03:26 jimmyo
# Added two new plugins contributed by Jacques Caruso, generic/exim_mailqueue_alt and generic/mailscanner.
#
#
# Magic markers:
#%# family=contrib
#%# capabilities=
use strict;
my $logfile = '/var/log/mail.log';
my $logtail = '/usr/sbin/logtail';
my $offsetfile = '@@PLUGSTATE@@/munin-mailscanner.offset';
my ($clean, $viruses, $spams, $others, $total) = (0, 0, 0, 0, 0);
my $cmd = (defined($ARGV[0])) ? $ARGV[0] : '';
(defined($ENV{'logfile'})) and $logfile = $ENV{'logfile'};
(defined($ENV{'logtail'})) and $logtail = $ENV{'logtail'};
(defined($ENV{'offsetfile'})) and $offsetfile = $ENV{'offsetfile'};
if ($cmd eq 'config') {
print("graph_title MailScanner statistics\n");
print("graph_args --lower-limit 0\n");
print("graph_vlabel messages\n");
print("clean.label clean\n");
print("clean.type GAUGE\n");
print("clean.draw LINE2\n");
print("viruses.label viruses\n");
print("viruses.type GAUGE\n");
print("viruses.draw LINE2\n");
print("spams.label spams\n");
print("spams.type GAUGE\n");
print("spams.draw LINE2\n");
print("others.label others\n");
print("others.type GAUGE\n");
print("others.draw LINE2\n");
print("total.label total\n");
print("total.type GAUGE\n");
print("total.draw LINE2\n");
exit(0);
}
my @lines = split(/\n/, qx($logtail -f $logfile -o $offsetfile));
foreach (@lines) {
SWITCH: {
if (/New Batch: S/) {
s/.*New Batch: Scanning ([0-9]+) messages.*/$1/;
$total += $_;
last SWITCH;
}
if (/Virus Scanning: F/) {
s/.*Virus Scanning: Found ([0-9]+) viruses.*/$1/g;
$viruses += $_;
last SWITCH;
}
if (/Spam Checks: F/) {
s/.*Spam Checks: Found ([0-9]+) spam.*/$1/g;
$spams += $_;
last SWITCH;
}
if (/Other Checks: F/) {
s/.*Other Checks: Found ([0-9]+) problems.*/$1/g;
$others += $_;
last SWITCH;
}
}
}
$clean = $total - ($viruses + $spams + $others);
print("clean.value $clean\n");
print("viruses.value $viruses\n");
print("spams.value $spams\n");
print("others.value $others\n");
print("total.value $total\n");
exit(0);
|