Postfix-Statistiken aus Daten, die vom Mailgraph-Daemon in RRD-Files gesammelt werden
#!/usr/bin/perl
use Getopt::Long;
use File::stat;
use lib "/usr/lib/nagios/plugins";
use utils qw (%ERRORS &print_revision);
use RRDs;
#########################################################
#########################################################
my $VERSION="0.1";
my $PROGNAME="check_rrdmail";
my $AUTHOR="Michael Mende ";
#########################################################
#########################################################
my ($opt_c, $opt_f, $opt_w, $opt_C, $opt_W, $opt_h, $opt_V);
my (%warn,%crit);
Getopt::Long::Configure('bundling');
GetOptions(
"V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
);
if ($opt_V) {
print_revision $PROGNAME,$VERSION;
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
if ($opt_c) {
}
sub print_usage () {
print "Usage: $PROGNAME -w -c [-t ]\n";
}
sub print_help () {
print_revision($PROGNAME,$VERSION);
print "\n";
print "Copyright (c) 2010 $AUTHOR\n";
print "\n";
print_usage();
print "\n";
print " Checks the number of messages handled by your mail server\n";
print "-w (--warning) = Min. number of messages in queue to generate warning\n";
print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w now - 2*OFFSET (~16 minutes)
my $stat = stat($rrdfile);
unless ($stat) {
print "UNKNOWN - ${rrdfile}: $!\n";
exit $ERRORS{'UNKNOWN'};
}
unless ($stat->mtime >= $ctime-2*$offset) {
my $ftime = localtime($stat->mtime);
print "UNKNOWN - $rrdfile too old \(mtime: $ftime\), check mailgraph daemon\n";
exit $ERRORS{'UNKNOWN'};
}
# rrd fetch
my $rrdlast = RRDs::last($rrdfile);
unless ($rrdlast >= $ctime-2*$offset) {
print "UNKNOWN - $rrdfile last entry too old \($rrdlast\), check mailgraph daemon\n";
exit $ERRORS{'UNKNOWN'};
}
my ($start,$step,$names,$data) = RRDs::fetch($rrdfile, "AVERAGE", "-e", @{[int($ctime/$resolution)*$resolution]}-$offset, "-s", "e-$resolution", "-r", $resolution);
unless ($start && $step && $names && $data) {
print "UNKNOWN - rrd fetch failed, check ${rrdfile}\n";
exit $ERRORS{'UNKNOWN'};
}
my %res;
@warn{@$names} = split /:/, $opt_w;
@crit{@$names} = split /:/, $opt_c;
for my $line (reverse @$data) {
@res{@$names} = map {sprintf "%.2f", $_*60} @$line;
}
$EXIT=$ERRORS{'OK'};
foreach $key (keys %res) {
if ($crit{$key} && $crit{$key}
#---
#NagiosGrapherTemplate for check_rrdmail
#---
# @ Michael Mende
#
# * change service_name whenever changing nagios service alias
# PIPE: master02 Postfix Mail Stats OK - rejected: 0 recv: 21 bounced: 17 sent: 13 mails/min rejected=0.00;;: recv=21.50;;: bounced=17.00;;: sent=13.00;;: mails/min
define ngraph{
service_name Postfix Mail Stats
graph_perf_regex rejected=(\d+.\d+)
graph_value rejected
graph_units mails/min
graph_legend rejected:
rrd_plottype LINE2
rrd_color EACC00
print_format %6.2lf
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source rejected
print_description Last:
print_function LAST
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source rejected
print_description Min:
print_function MIN
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source rejected
print_description Max:
print_function MAX
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source rejected
print_description Avg:
print_function AVERAGE
print_format %6.2lf
print_eol left
}
##########
define ngraph{
service_name Postfix Mail Stats
graph_perf_regex bounced=(\d+.\d+)
graph_value bounced
graph_units mails/min
graph_legend bounced :
rrd_plottype LINE2
rrd_color FF0000
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source bounced
print_description Last:
print_function LAST
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source bounced
print_description Min:
print_function MIN
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source bounced
print_description Max:
print_function MAX
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source bounced
print_description Avg:
print_function AVERAGE
print_format %6.2lf
print_eol left
}
##########
define ngraph{
service_name Postfix Mail Stats
graph_perf_regex recv=(\d+.\d+)
graph_value recv
graph_units mails/min
graph_legend received:
rrd_plottype LINE2
rrd_color 00FF00
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source recv
print_description Last:
print_function LAST
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source recv
print_description Min:
print_function MIN
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source recv
print_description Max:
print_function MAX
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source recv
print_description Avg:
print_function AVERAGE
print_format %6.2lf
print_eol left
}
##########
define ngraph{
service_name Postfix Mail Stats
graph_perf_regex sent=(\d+.\d+)
graph_value sent
graph_units mails/min
graph_legend sent :
rrd_plottype LINE2
rrd_color 0000FF
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source sent
print_description Last:
print_function LAST
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source sent
print_description Min:
print_function MIN
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source sent
print_description Max:
print_function MAX
print_format %6.2lf
# print_eol left
}
define ngraph{
service_name Postfix Mail Stats
type GPRINT
print_source sent
print_description Avg:
print_function AVERAGE
print_format %6.2lf
print_eol left
}
#[EOF]