From: Stephen L Johnson Date: Mon, 21 Aug 2000 19:35:17 +0000 (+0000) Subject: updated to handle multiple mail queue dirs of sendmail 8.10 and higher X-Git-Tag: spong-2_7_0-beta1~64 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85df2758a1f30b0b1c17a644bad08d816fcd65f1;p=spong.git updated to handle multiple mail queue dirs of sendmail 8.10 and higher --- diff --git a/src/lib/Spong/Client/plugins/check_mailq b/src/lib/Spong/Client/plugins/check_mailq index aa807f4..79beb10 100755 --- a/src/lib/Spong/Client/plugins/check_mailq +++ b/src/lib/Spong/Client/plugins/check_mailq @@ -1,30 +1,68 @@ # Register routine with plugin registery $CHECKFUNCS{'mailq'} = \&check_mailq; +# $Id: check_mailq,v 1.2 2000/08/21 19:35:17 sljohnson Exp $ + # Sendmail mailq check for mail servers. If checks the numeber of mail # message queue against the $MAILQWARN AND $MAILQCRIT variables +use File::Basename; + sub check_mailq { - my($mqcnt, $message, $color, $summary ); + my($mqcnt, $message, $color, $summary ); + my(%qcnt,$singleq,@problems); + + $singlq = 0; + open (FOO,"$MAILQ |"); + $mqcnt = 0; + while () { + if (/Mail Queue\s+\((\d+)/) { $mqcnt = $1; $singleq=1; } + elsif (/Total Requests:\s+(\d+)/) { $mqcnt = $1; } + elsif (/\s+(\S+)\s+\((\d+)/) { $qcnt{$1} = $2; } + elsif (/(\S+)\s+is empty/) { $qcnt{$1} = 0; } + + # If sendmail is pre 8.10, just grab the first few entries for message + if ($singleq) { + # Grab the first 10 entries. + if (++$lines <= 35) { $message .= $_; } else {last;}; + } + } + close FOO; - open (FOO,"$MAILQ |"); - $mqcnt = 0; - while () { - if (/Mail Queue\s+\((\d+)/) { $mqcnt = $1; } + $color = "green"; + if ($mqcnt > $MAILQWARN) { $color = "yellow"; } + if ($mqcnt > $MAILQCRIT) { $color = "red"; } + $summary = "Mail Queue count = $mqcnt"; - # Grab the first 10 entries. - if (++$lines <= 35) { $message .= $_ }; - } - close FOO; + if ( ! $singleq) { + for my $q (sort(keys %qcnt)) { + $message .= "queue $q ($qcnt{$q} requests)\n"; - $color = "green"; - if ($mqcnt > $MAILQWARN) { $color = "yellow"; } - if ($mqcnt > $MAILQCRIT) { $color = "red"; } + if ( defined $MAILQ_SUBQ_CRIT && $qcnt{$q} >= $MAILQ_SUBQ_CRIT ) { + $color = "red"; + push @problems,$q; + } + elsif ( defined $MAILQ_SUBQ_WARN && $qcnt{$q} >= $MAILQ_SUBQ_WARN ) { + $color = "yellow" unless $color eq "red"; + push @problems,$q; + } + } - $summary = "Mail Queue count = $mqcnt"; + if( $#problems == 0 ) { + my $baseq = basename($problems[0]); + $summary .= ", que $baseq has " . $qcnt{$problems[0]} . " requests"; + } + elsif( $#problems > 0 ) { + $summary .= ", multiple problems: "; + foreach my $q (@problems) { + my $baseq = basename($q); + $summary .= "que $baseq (" . $qcnt{$q} . "),"; + } + } + } - &debug("mailq - $color, $summary"); - &status( $SPONGSERVER, $HOST, "mailq", $color, $summary, $message ); + &debug("mailq - $color, $summary"); + &status( $SPONGSERVER, $HOST, "mailq", $color, $summary, $message ); } # I'm include perl code, I need this line.