diff options
-rwxr-xr-x | plugins-scripts/check_mailq.pl | 88 |
1 files changed, 86 insertions, 2 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 23bc521f..0505207b 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
@@ -293,6 +293,90 @@ if ($mailq eq "sendmail") { | |||
293 | } | 293 | } |
294 | 294 | ||
295 | } # end of ($mailq eq "sendmail") | 295 | } # end of ($mailq eq "sendmail") |
296 | elsif ( $mailq eq "postfix" ) { | ||
297 | |||
298 | ## open mailq | ||
299 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | ||
300 | if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { | ||
301 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | ||
302 | exit $ERRORS{'UNKNOWN'}; | ||
303 | } | ||
304 | }elsif( defined $utils::PATH_TO_MAILQ){ | ||
305 | unless (-x $utils::PATH_TO_MAILQ) { | ||
306 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; | ||
307 | exit $ERRORS{'UNKNOWN'}; | ||
308 | } | ||
309 | } else { | ||
310 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; | ||
311 | exit $ERRORS{'UNKNOWN'}; | ||
312 | } | ||
313 | |||
314 | |||
315 | @lines = reverse <MAILQ>; | ||
316 | |||
317 | # close qmail-qstat | ||
318 | close MAILQ; | ||
319 | # declare an error if we also get a non-zero return code from mailq | ||
320 | # unless already set to critical | ||
321 | if ( $? ) { | ||
322 | $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ; | ||
323 | print "STDERR $?: $!\n" if $verbose; | ||
324 | $msg = "$state: (stderr)\n"; | ||
325 | } | ||
326 | |||
327 | ## shut off the alarm | ||
328 | alarm(0); | ||
329 | |||
330 | # check queue length | ||
331 | if ($lines[0]=~/Kbytes in (\d+)/) { | ||
332 | $msg_q = $1 ; | ||
333 | }elsif ($lines[0]=~/Mail queue is empty/) { | ||
334 | $msg_q = 0; | ||
335 | }else{ | ||
336 | print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; | ||
337 | exit $ERRORS{'UNKNOWN'}; | ||
338 | } | ||
339 | |||
340 | # check messages not processed | ||
341 | #if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) { | ||
342 | # my $msg_p = $1; | ||
343 | #}else{ | ||
344 | # print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; | ||
345 | # exit $ERRORS{'UNKNOWN'}; | ||
346 | #} | ||
347 | |||
348 | # check queue length(s) | ||
349 | if ($msg_q == 0){ | ||
350 | $msg = "OK: mailq reports queue is empty"; | ||
351 | $state = $ERRORS{'OK'}; | ||
352 | } else { | ||
353 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; | ||
354 | |||
355 | # overall queue length | ||
356 | if ($msg_q < $opt_w) { | ||
357 | $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; | ||
358 | $state = $ERRORS{'OK'}; | ||
359 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { | ||
360 | $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)"; | ||
361 | $state = $ERRORS{'WARNING'}; | ||
362 | }else { | ||
363 | $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)"; | ||
364 | $state = $ERRORS{'CRITICAL'}; | ||
365 | } | ||
366 | |||
367 | # check messages not yet preprocessed (only compare is $opt_W and $opt_C | ||
368 | # are defined) | ||
369 | |||
370 | #if (defined $opt_W) { | ||
371 | # $msg .= "[Preprocessed = $msg_p]"; | ||
372 | # if ($msg_p >= $opt_W && $msg_p < $opt_C ) { | ||
373 | # $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ; | ||
374 | # }elsif ($msg_p >= $opt_C ) { | ||
375 | # $state = $ERRORS{"CRITICAL"} ; | ||
376 | # } | ||
377 | #} | ||
378 | } | ||
379 | } # end of ($mailq eq "postfixl") | ||
296 | elsif ( $mailq eq "qmail" ) { | 380 | elsif ( $mailq eq "qmail" ) { |
297 | 381 | ||
298 | # open qmail-qstat | 382 | # open qmail-qstat |
@@ -442,7 +526,7 @@ sub process_arguments(){ | |||
442 | } | 526 | } |
443 | 527 | ||
444 | if (defined $opt_M) { | 528 | if (defined $opt_M) { |
445 | if ($opt_M =~ /sendmail/ || $opt_M =~ /qmail/ ) { | 529 | if ($opt_M =~ /sendmail/ || $opt_M =~ /qmail/ || $opt_M =~ /postfix/ ) { |
446 | $mailq = $opt_M ; | 530 | $mailq = $opt_M ; |
447 | }elsif( $opt_M eq ''){ | 531 | }elsif( $opt_M eq ''){ |
448 | $mailq = 'sendmail'; | 532 | $mailq = 'sendmail'; |
@@ -474,7 +558,7 @@ sub print_help () { | |||
474 | print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; | 558 | print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; |
475 | print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; | 559 | print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; |
476 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 560 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
477 | print "-M (--mailserver) = [ sendmail | qmail ] (default = sendmail)\n"; | 561 | print "-M (--mailserver) = [ sendmail | qmail | postfix ] (default = sendmail)\n"; |
478 | print "-h (--help)\n"; | 562 | print "-h (--help)\n"; |
479 | print "-V (--version)\n"; | 563 | print "-V (--version)\n"; |
480 | print "-v (--verbose) = debugging output\n"; | 564 | print "-v (--verbose) = debugging output\n"; |