The "mailq" command reads the headers of each message, if there are many
thousands of messages that can regularly take long enough to cause a timeout.
The following patch (against version 1.4.12-5) adds a new option -M
postfix-fast to use find instead of mailq, it usually runs about 1,000 times
faster!
The same bug appears to be present in 1.4.14-5, I will make and test a patch
for that shortly and update this bug report accordingly.
--- /usr/lib/nagios/plugins/check_mailq 2010-06-24 09:32:13.000000000 +0000
+++ ./check_mailq 2010-06-30 03:20:07.000000000 +0000
@@ -293,6 +293,43 @@
}
} # end of ($mailq eq "sendmail")
+elsif ( $mailq eq "postfix-fast" ) {
+ if (! open (MAILQ, "/usr/bin/find /var/spool/postfix/defer /var/spool/postfix/hold -type f|/usr/bin/wc -l|") ) {
+ print "ERROR: could not run find on the mail spool \n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+ $msg_q = <MAILQ>;
+ close MAILQ;
+
+ if ( $? ) {
+ print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+ exit $ERRORS{CRITICAL};
+ }
+
+ ## shut off the alarm
+ alarm(0);
+
+ # check queue length(s)
+ if ($msg_q == 0){
+ $msg = "OK: mailq reports queue is empty";
+ $state = $ERRORS{'OK'};
+ } else {
+ print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
+
+ # overall queue length
+ if ($msg_q < $opt_w) {
+ $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
+ $state = $ERRORS{'OK'};
+ }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
+ $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)";
+ $state = $ERRORS{'WARNING'};
+ }else {
+ $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)";
+ $state = $ERRORS{'CRITICAL'};
+ }
+ }
+
+} # end of ( $mailq eq "postfix-fast" )
elsif ( $mailq eq "postfix" ) {
## open mailq
@@ -374,7 +411,7 @@
# }
#}
}
-} # end of ($mailq eq "postfixl")
+} # end of ($mailq eq "postfix")
elsif ( $mailq eq "qmail" ) {
# open qmail-qstat
@@ -560,7 +597,7 @@
}
if (defined $opt_M) {
- if ($opt_M =~ /^(sendmail|qmail|postfix|exim)$/) {
+ if ($opt_M =~ /^(sendmail|qmail|postfix|postfix-fast|exim)$/) {
$mailq = $opt_M ;
}elsif( $opt_M eq ''){
$mailq = 'sendmail';