# 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 (<FOO>) {
+ 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 (<FOO>) {
- 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.