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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
#!@@PERL@@
#
# Plugin to monitor the number of mails received and delivered by exim.
#
# Usage: copy or link into /etc/munin/node.d/
#
# Parameters:
#
# config (required)
# autoconf (optional - used by munin-config)
#
# Config variables:
#
# logdir - Override what exim says
# exim - Where's exim?
#
# $Log$
# Revision 1.7.2.2 2005/03/12 23:07:17 jimmyo
# Avoid negative spike in generic/exim_mailstats.
#
# Revision 1.7.2.1 2005/03/09 19:24:12 jimmyo
# Thanks to Stephen Gran, generic/exim_mailstats now graphs rejects (Deb#295799).
#
# Revision 1.7 2004/12/10 18:51:43 jimmyo
# linux/apt* has been forced to LANG=C, to get predictable output.
#
# Revision 1.6 2004/12/10 10:47:47 jimmyo
# Change name from ${scale} to ${graph_period}, to be more consistent.
#
# Revision 1.5 2004/12/09 22:12:54 jimmyo
# Added "graph_period" option, to make "graph_sums" usable.
#
# Revision 1.4 2004/11/21 00:16:56 jimmyo
# Changed a lot of plugins so they use DERIVE instead of COUNTER.
#
# Revision 1.3 2004/11/10 15:54:49 jimmyo
# Applied patch from Torstein T. Svendsen to generic/exim_mailstats, to handle logfiles with timestamps in the name (SF#1055214)
#
# Revision 1.2 2004/05/20 13:57:12 jimmyo
# Set categories to some of the plugins.
#
# Revision 1.1 2004/01/02 18:50:00 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.7 2003/11/15 11:10:28 jimmyo
# Various fixes
#
# Revision 1.6 2003/11/07 17:43:16 jimmyo
# Cleanups and log entries
#
#
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf
sub get_exim_logfile {
my ($spec, $type, $time) = @_;
chomp($spec);
$time = time() unless $time;
my $logfile = $spec;
$logfile =~ s/^log_file_path = //;
$logfile =~ s/\%s/$type/;
if( $logfile =~ /\%D/ ) {
my @t=localtime($time);
my $ts = sprintf("%04d%02d%02d",$t[5]+1900, $t[4]+1, $t[3]);
$logfile =~ s/\%D/$ts/g;
}
my @lfiles = split(/\s?:\s?/, $logfile);
foreach (@lfiles) {
return $_ unless /^syslog/;
}
}
$statefile = "@@PLUGSTATE@@/plugin-exim_mailstats.state";
$pos = undef;
$received = 0;
$completed = 0;
$rejected = 0;
($dirname = $0) =~ s/[^\/]+$//;
$EXIM = "/usr/sbin/exim";
$EXIM = "/usr/sbin/exim4" if (-x "/usr/sbin/exim4"); # a Debianism
$EXIM = $ENV{'exim'} if defined $ENV{'exim'};
$LOGDIR = $ENV{'logdir'} || undef;
if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
{
my $logfile;
if(defined($LOGDIR)) {
if(! -d $LOGDIR) {
print "no (logdir does not exist)\n";
exit(1);
}
$logfile = $LOGDIR . '/mainlog';
} else {
my $logfilespec = `$EXIM -bP log_file_path 2>/dev/null`;
if (! $?)
{
$logfile = get_exim_logfile( $logfilespec, 'main');
}
elsif ($? eq "127")
{
print "no (exim not found)\n";
}
else
{
print "no\n";
}
}
if ($logfile)
{
if (-r "$logfile")
{
print "yes\n";
exit 0;
}
else
{
print "no (logfile not readable)\n";
}
}
exit 1;
}
my $logfilespec;
if(defined($LOGDIR)) {
$logfilespec = '';
$logfile = $LOGDIR . '/' . 'mainlog';
} else {
$logfilespec = `$EXIM -bP log_file_path`;
$logfile = get_exim_logfile( $logfilespec, 'main');
}
exit 1 unless -r $logfile;
if( $logfilespec =~ /\%D/ ) {
$rotlogfile = get_exim_logfile( $logfilespec, 'main', (time()-(24*60*60)));
} else {
if (-f "$logfile.0")
{
$rotlogfile = $logfile . ".0";
}
elsif (-f "$logfile.1")
{
$rotlogfile = $logfile . ".1";
}
elsif (-f "$logfile.01")
{
$rotlogfile = $logfile . ".01";
}
else
{
$rotlogfile = $logfile . ".0";
}
}
if ( $ARGV[0] and $ARGV[0] eq "config" )
{
print "graph_title Exim mail throughput\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel mails/\${graph_period}\n";
print "graph_scale no\n";
print "graph_category exim\n";
print "received.label received\n";
print "received.type DERIVE\n";
print "received.min 0\n";
print "received.draw AREA\n";
print "completed.label completed\n";
print "completed.type DERIVE\n";
print "completed.min 0\n";
print "rejected.label rejected\n";
print "rejected.type DERIVE\n";
print "rejected.min 0\n";
exit 0;
}
if (! -f $logfile and ! -f $rotlogfile)
{
print "completed.value U\n";
print "received.value U\n";
print "rejected.value U\n";
exit 0;
}
if (-f "$statefile")
{
open (IN, "$statefile") or exit 4;
my $in = <IN>;
if ($in =~ /^(\d+):(\d+):(\d+):(\d+)/)
{
($pos, $received, $completed, $rejected) = ($1, $2, $3, $4);
}
elsif ($in =~ /^(\d+):(\d+):(\d+)/)
{
($pos, $received, $completed) = ($1, $2, $3);
$rejected = 0;
}
close IN;
}
$startsize = (stat $logfile)[7];
if (!defined $pos)
{
# Initial run.
$pos = $startsize;
}
if ($startsize < $pos)
{
# Log rotated
parseEximfile ($rotlogfile, $pos, (stat $rotlogfile)[7]);
$pos = 0;
}
parseEximfile ($logfile, $pos, $startsize);
$pos = $startsize;
print "received.value $received\n";
print "completed.value $completed\n";
print "rejected.value $rejected\n";
if(-l $statefile) {
die("$statefile is a symbolic link, refusing to touch it.");
}
open (OUT, ">$statefile") or exit 4;
print OUT "$pos:$received:$completed:$rejected\n";
close OUT;
sub parseEximfile
{
my ($fname, $start, $stop) = @_;
open (LOGFILE, $fname) or exit 3;
seek (LOGFILE, $start, 0) or exit 2;
while (tell (LOGFILE) < $stop)
{
my $line =<LOGFILE>;
chomp ($line);
if (substr ($line, 37,2 ) eq '<=')
{
$received++;
}
elsif (substr ($line, 37,9) eq 'Completed')
{
$completed++;
}
elsif ($line=~/rejected/)
{
$rejected++;
}
}
close(LOGFILE);
}
# vim:syntax=perl
|