6
courier_mta_mailstats - Plugin to monitor the number of mails
7
delivered and rejected by courier-mta.
11
The following environment variables are used:
13
logdir - Where to find logfiles (default "/var/log")
14
logfile - What file to read in logdir (default "mail.log")
15
courier - Path to "courier" (default "/usr/sbin/courier")
19
Rune Nordb�e Skillingstad <runesk@linpro.no>
28
#%# capabilities=autoconf
32
my $statefile = "@@PLUGSTATE@@/munin-plugin-courier_mta_mailstats.state";
36
my $LOGDIR = $ENV{'logdir'} || '/var/log';
37
my $LOGFILE = $ENV{'logfile'} || 'mail.log';
38
my $COURIER = $ENV{'courier'} || '/usr/sbin/courier';
40
if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
45
$logfile = "$LOGDIR/$LOGFILE";
51
print "no (logfile not readable)\n";
54
print "no (logfile not found)\n";
57
print "no (could not find logdir)\n";
60
print "no (could not find executable)\n";
65
my $logfile = "$LOGDIR/$LOGFILE";
66
my $prevdate = get_prev_date();
68
if(-f "$logfile.$prevdate") {
69
$rotlogfile = "$logfile.$prevdate";
70
} elsif (-f "$logfile.0") {
71
$rotlogfile = $logfile . ".0";
72
} elsif (-f "$logfile.1") {
73
$rotlogfile = $logfile . ".1";
74
} elsif (-f "$logfile.01") {
75
$rotlogfile = $logfile . ".01";
77
$rotlogfile = $logfile . ".0";
81
open (IN, "$statefile") or exit 4;
82
if(<IN> =~ /^(\d+):(\d+)/) {
83
($pos, $delivered) = ($1, $2);
86
if (/^(\d+):(\d+)$/) {
93
if(! -f $logfile and ! -f $rotlogfile) {
94
print "delivered.value U\n";
95
foreach my $i (keys %{$rejects}) {
96
print "r$i.value U\n";
102
$startsize = (stat $logfile)[7];
109
if($startsize < $pos) {
111
parseLogfile ($rotlogfile, $pos, (stat $rotlogfile)[7]);
115
parseLogfile ($logfile, $pos, $startsize);
118
if($ARGV[0] and $ARGV[0] eq "config") {
119
print "graph_title Courier MTA mail throughput\n";
120
print "graph_args --base 1000 -l 0\n";
121
print "graph_vlabel mails / \${graph_period}\n";
122
print "graph_scale no\n";
123
print "graph_total Total\n";
124
print "delivered.label delivered\n";
125
print "delivered.type DERIVE\n";
126
print "delivered.draw AREA\n";
127
print "delivered.min 0\n";
128
foreach my $i (keys %{$rejects}) {
129
print "r$i.label reject $i\n";
130
print "r$i.type DERIVE\n";
131
print "r$i.draw STACK\n";
137
print "delivered.value $delivered\n";
138
foreach my $i (keys %{$rejects}) {
139
print "r$i.value ", $rejects->{$i}, "\n";
143
die("$statefile is a symbolic link, refusing to touch it.");
145
open (OUT, ">$statefile") or exit 4;
146
print OUT "$pos:$delivered\n";
147
foreach my $i (keys %{$rejects}) {
148
print OUT "$i:", $rejects->{$i}, "\n";
153
my ($fname, $start, $stop) = @_;
154
open (LOGFILE, $fname) or exit 3;
155
seek (LOGFILE, $start, 0) or exit 2;
157
while (tell (LOGFILE) < $stop) {
160
if($line =~ /(?:courierlocal|courieresmtp): id=.*,from=.*,addr=.*,size=\d+,success:.*delivered/) {
162
} elsif($line =~ /courieresmtpd: error,relay=.*(?:\d{1,3}\.){3}\d{1,3},from=[^:]+: (\d{3})/) {
170
my @date = localtime (time - 86400);
171
my $prevdate = $date[5]+1900 . $date[4]+1 . $date[3];