diff -r e5c47baa6743 -r ec3c5514cd94 check_exim.pl --- a/check_exim.pl Wed Dec 19 21:26:07 2007 +0000 +++ b/check_exim.pl Wed Dec 19 21:59:39 2007 +0000 @@ -1,6 +1,13 @@ #! /usr/bin/perl # $Id$ # $URL$ +my $USAGE = <<'#'; +Usage: $ME --init + $ME {-w|--warning rate} {-c|--crit rate} + + rate is in mails/h + +# use strict; use warnings; @@ -28,8 +35,10 @@ ); my %opt = (init => undef, + cleanup => undef, warn => undef, crit => undef, + help => undef, update => 1, ); @@ -45,6 +54,7 @@ ); sub init(); +sub cleanup(); MAIN: { @@ -52,9 +62,17 @@ "warn=s" => \$opt{warn}, # rate mails/h "crit=s" => \$opt{crit}, # rate mails/h "update!" => \$opt{update}, + "cleanup"=> \$opt{cleanup}, + "help" => \$opt{help}, ) or die "Bad Usage\n"; + if ($opt{help}) { + print eval qq{"$USAGE"}; + exit 0; + } + $opt{init} and do { init(); exit }; + $opt{cleanup} and do { cleanup(); exit }; # read the exim (cache) file and the status die "$0: $CACHE_FILE not found ($!). Try $0 --help\n" @@ -185,6 +203,15 @@ } +sub cleanup() { + unlink $STATE_FILE, $CACHE_FILE; + foreach ($STATE_FILE, $CACHE_FILE) { + while ("/" ne ($_ = dirname($_))) { + rmdir; + } + } +} + sub init() { # noch sind wir root (hoffentlich) @@ -232,15 +259,4 @@ __END__ -my $FILE = "/var/log/exim4/mainlog"; -my $STATUS = "/var/run/nagios3/$ME/%s"; - -sub unkn(@) { print "UNKNOWN @_\n"; exit 3 } -sub crit(@) { print "CRIT @_\n"; exit 2 } -sub warn(@) { print "WARN @_\n"; exit 1 } -sub ok(@) { print "OK @_\n"; exit 0 } - -open(my $log, $FILE) or critical("file $FILE not found"); - -__END__ # vim:sts=4 sw=4 aw ai sm: