#587590 nagios-plugins-basic: Please add the attached patch for faster checking of Postfix queues

#587590#5
Date:
2010-06-30 03:26:53 UTC
From:
To:
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';

#587590#12
Date:
2010-06-30 09:24:25 UTC
From:
To:
Hi Russell,

thanks for your bugreport. From my side, I wouldn't love to carry this kind of
patch over long time, without getting it applied upstream. So we need to get
it into there first. I asked Ton about integration and he requests two things
as requirements, which sounds reasonable for me:

* find/wc needs converted to pure perl (using File::Find which is part of core
perl)
* postfix paths should be discovered/configurable by ./configure

So if the patch fits this, I would happily forward it to upstream and if it
gets accepted into SCM, I will apply it to the package asap.

Thanks and with kind regards, Jan.

#587590#21
Date:
2011-05-14 14:17:41 UTC
From:
To:
tag 587590 + wontfix
thanks

Hi Russell,

After round about 1 year without feedback, I will tag this bug wontfix. Feel
free to get back to us, if there is a patch available which may get accepted
by upstream.

With kind regards, Jan.