/usr/share/munin/plugins/postfix_mailstats is in munin-node 1.4.6-3ubuntu3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | #!/usr/bin/perl -w
# -*- perl -*-
=head1 NAME
postfix_mailstats - Plugin to monitor the number of mails delivered and
rejected by postfix
=head1 CONFIGURATION
Configuration parameters for /etc/munin/postfix_mailstats,
if you need to override the defaults below:
[postfix_mailstats]
env.logdir - Which logfile to use
env.logfile - What file to read in logdir
=head2 DEFAULT CONFIGURATION
[postfix_mailstats]
env.logdir /var/log
env.logfile mail.log
=head1 AUTHOR
Records show that the plugin was contributed by Nicolai Langfeldt in
2003. Nicolai can't find anything in his email about this and expects
the plugin is based on the corresponding exim plugin - to which it now
bears no resemblence.
=head1 LICENSE
Unknown license
=head1 MAGIC MARKERS
=begin comment
These magic markers are used by munin-node-configure when installing
munin-node.
=end comment
#%# family=manual
#%# capabilities=autoconf
=head1 RANDOM COMMENTS
Would be cool if someone ported this to Munin::Plugin for both state
file and log tailing.
=cut
my $statefile = $ENV{'MUNIN_PLUGSTATE'} . "/munin-plugin-postfix_mailstats.state";
my $pos;
my $delivered = 0;
my $rejects = {};
my $LOGDIR = $ENV{'logdir'} || '/var/log';
my $LOGFILE = $ENV{'logfile'} || 'mail.log';
my $logfile = "$LOGDIR/$LOGFILE";
if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
{
my $logfile;
if (-d $LOGDIR)
{
if (-f $logfile)
{
if (-r $logfile)
{
print "yes\n";
exit 0;
}
else
{
print "no (logfile '$logfile' not readable)\n";
}
}
else
{
print "no (logfile '$logfile' not found)\n";
}
}
else
{
print "no (could not find logdir '$LOGDIR')\n";
}
exit 0;
}
if ( -f $statefile)
{
open (IN, '<', $statefile) or die "Unable to open state-file: $!\n";
if (<IN> =~ /^(\d+):(\d+)/)
{
($pos, $delivered) = ($1, $2);
}
while (<IN>)
{
if (/^([0-9a-z.\-]+):(\d+)$/)
{
$rejects->{$1} = $2;
}
}
close IN;
}
if (! -f $logfile)
{
print "delivered.value U\n";
foreach my $i (sort keys %{$rejects})
{
print "r$i.value U\n";
}
exit 0;
}
$startsize = (stat $logfile)[7];
if (!defined $pos)
{
# Initial run.
$pos = $startsize;
}
parseLogfile($logfile, $pos, $startsize);
$pos = $startsize;
if ( $ARGV[0] and $ARGV[0] eq "config" )
{
print "graph_title Postfix message throughput\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel mails / \${graph_period}\n";
print "graph_scale no\n";
print "graph_total Total\n";
print "graph_category postfix\n";
print "delivered.label delivered\n";
print "delivered.type DERIVE\n";
print "delivered.draw AREA\n";
print "delivered.min 0\n";
foreach my $i (sort keys %{$rejects})
{
print "r$i.label reject $i\n";
print "r$i.type DERIVE\n";
print "r$i.draw STACK\n";
print "r$i.min 0\n";
}
exit 0;
}
print "delivered.value $delivered\n";
foreach my $i (sort keys %{$rejects})
{
print "r$i.value ", $rejects->{$i}, "\n";
}
if(-l $statefile) {
die("$statefile is a symbolic link, refusing to touch it.");
}
open (OUT, '>', $statefile) or die "Unable to open statefile: $!\n";
print OUT "$pos:$delivered\n";
foreach my $i (sort keys %{$rejects})
{
print OUT "$i:", $rejects->{$i}, "\n";
}
close OUT;
sub parseLogfile
{
my ($fname, $start, $stop) = @_;
open (LOGFILE, $fname)
or die "Unable to open logfile $fname for reading: $!\n";
seek (LOGFILE, $start, 0)
or die "Unable to seek to $start in $fname: $!\n";
while (tell (LOGFILE) < $stop)
{
my $line = <LOGFILE>;
chomp ($line);
if ($line =~ /qmgr.*from=.*size=[0-9]*/)
{
$delivered++;
}
elsif ($line =~ /postfix\/smtpd.*reject: \S+ \S+ \S+ (\S+)/ ||
$line =~ /postfix\/cleanup.* reject: (\S+)/)
{
$rejects->{$1}++;
}
}
close(LOGFILE) or warn "Error closing $fname: $!\n";
}
# vim:syntax=perl
|