summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_mailq.pl
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/check_mailq.pl')
-rwxr-xr-xplugins-scripts/check_mailq.pl105
1 files changed, 84 insertions, 21 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 1d0a3ad..488cf2f 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -20,8 +20,8 @@
20# 20#
21# You should have received a copy of the GNU General Public License 21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software 22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24# 24# USA
25# 25#
26############################################################################ 26############################################################################
27 27
@@ -31,7 +31,8 @@ use Getopt::Long;
31use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t 31use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t
32 $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines 32 $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines
33 %srcdomains %dstdomains); 33 %srcdomains %dstdomains);
34use lib utils.pm; 34use FindBin;
35use lib "$FindBin::Bin";
35use utils qw(%ERRORS &print_revision &support &usage ); 36use utils qw(%ERRORS &print_revision &support &usage );
36 37
37 38
@@ -199,20 +200,20 @@ if ($mailq eq "sendmail") {
199 ## now check the queue length(s) 200 ## now check the queue length(s)
200 201
201 if ($msg_q == 0) { 202 if ($msg_q == 0) {
202 $msg = "OK: mailq is empty"; 203 $msg = "OK: $mailq mailq is empty";
203 $state = $ERRORS{'OK'}; 204 $state = $ERRORS{'OK'};
204 } else { 205 } else {
205 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; 206 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
206 207
207 # overall queue length 208 # overall queue length
208 if ($msg_q < $opt_w) { 209 if ($msg_q < $opt_w) {
209 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; 210 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
210 $state = $ERRORS{'OK'}; 211 $state = $ERRORS{'OK'};
211 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { 212 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
212 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)"; 213 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
213 $state = $ERRORS{'WARNING'}; 214 $state = $ERRORS{'WARNING'};
214 }else { 215 }else {
215 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)"; 216 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
216 $state = $ERRORS{'CRITICAL'}; 217 $state = $ERRORS{'CRITICAL'};
217 } 218 }
218 219
@@ -344,20 +345,20 @@ elsif ( $mailq eq "postfix" ) {
344 345
345 # check queue length(s) 346 # check queue length(s)
346 if ($msg_q == 0){ 347 if ($msg_q == 0){
347 $msg = "OK: mailq reports queue is empty"; 348 $msg = "OK: $mailq mailq reports queue is empty";
348 $state = $ERRORS{'OK'}; 349 $state = $ERRORS{'OK'};
349 } else { 350 } else {
350 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; 351 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
351 352
352 # overall queue length 353 # overall queue length
353 if ($msg_q < $opt_w) { 354 if ($msg_q < $opt_w) {
354 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; 355 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
355 $state = $ERRORS{'OK'}; 356 $state = $ERRORS{'OK'};
356 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { 357 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
357 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)"; 358 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
358 $state = $ERRORS{'WARNING'}; 359 $state = $ERRORS{'WARNING'};
359 }else { 360 }else {
360 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)"; 361 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
361 $state = $ERRORS{'CRITICAL'}; 362 $state = $ERRORS{'CRITICAL'};
362 } 363 }
363 364
@@ -373,7 +374,7 @@ elsif ( $mailq eq "postfix" ) {
373 # } 374 # }
374 #} 375 #}
375 } 376 }
376} # end of ($mailq eq "postfixl") 377} # end of ($mailq eq "postfix")
377elsif ( $mailq eq "qmail" ) { 378elsif ( $mailq eq "qmail" ) {
378 379
379 # open qmail-qstat 380 # open qmail-qstat
@@ -431,13 +432,13 @@ elsif ( $mailq eq "qmail" ) {
431 432
432 # overall queue length 433 # overall queue length
433 if ($msg_q < $opt_w) { 434 if ($msg_q < $opt_w) {
434 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; 435 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
435 $state = $ERRORS{'OK'}; 436 $state = $ERRORS{'OK'};
436 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { 437 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
437 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)"; 438 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
438 $state = $ERRORS{'WARNING'}; 439 $state = $ERRORS{'WARNING'};
439 }else { 440 }else {
440 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)"; 441 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
441 $state = $ERRORS{'CRITICAL'}; 442 $state = $ERRORS{'CRITICAL'};
442 } 443 }
443 444
@@ -489,17 +490,54 @@ elsif ( $mailq eq "exim" ) {
489 exit $ERRORS{CRITICAL}; 490 exit $ERRORS{CRITICAL};
490 } 491 }
491 if ($msg_q < $opt_w) { 492 if ($msg_q < $opt_w) {
492 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; 493 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
493 $state = $ERRORS{'OK'}; 494 $state = $ERRORS{'OK'};
494 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { 495 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
495 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)"; 496 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
496 $state = $ERRORS{'WARNING'}; 497 $state = $ERRORS{'WARNING'};
497 }else { 498 }else {
498 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)"; 499 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
499 $state = $ERRORS{'CRITICAL'}; 500 $state = $ERRORS{'CRITICAL'};
500 } 501 }
501} # end of ($mailq eq "exim") 502} # end of ($mailq eq "exim")
502 503
504elsif ( $mailq eq "nullmailer" ) {
505 ## open mailq
506 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
507 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
508 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
509 exit $ERRORS{'UNKNOWN'};
510 }
511 }elsif( defined $utils::PATH_TO_MAILQ){
512 unless (-x $utils::PATH_TO_MAILQ) {
513 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
514 exit $ERRORS{'UNKNOWN'};
515 }
516 } else {
517 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
518 exit $ERRORS{'UNKNOWN'};
519 }
520
521 while (<MAILQ>) {
522 #2006-06-22 16:00:00 282 bytes
523
524 if (/^[1-9][0-9]*-[01][0-9]-[0-3][0-9]\s[0-2][0-9]\:[0-2][0-9]\:[0-2][0-9]\s{2}[0-9]+\sbytes$/) {
525 $msg_q++ ;
526 }
527 }
528 close(MAILQ) ;
529 if ($msg_q < $opt_w) {
530 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
531 $state = $ERRORS{'OK'};
532 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
533 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
534 $state = $ERRORS{'WARNING'};
535 }else {
536 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
537 $state = $ERRORS{'CRITICAL'};
538 }
539} # end of ($mailq eq "nullmailer")
540
503# Perfdata support 541# Perfdata support
504print "$msg|unsent=$msg_q;$opt_w;$opt_c;0\n"; 542print "$msg|unsent=$msg_q;$opt_w;$opt_c;0\n";
505exit $state; 543exit $state;
@@ -559,7 +597,7 @@ sub process_arguments(){
559 } 597 }
560 598
561 if (defined $opt_M) { 599 if (defined $opt_M) {
562 if ($opt_M =~ /^(sendmail|qmail|postfix|exim)$/) { 600 if ($opt_M =~ /^(sendmail|qmail|postfix|exim|nullmailer)$/) {
563 $mailq = $opt_M ; 601 $mailq = $opt_M ;
564 }elsif( $opt_M eq ''){ 602 }elsif( $opt_M eq ''){
565 $mailq = 'sendmail'; 603 $mailq = 'sendmail';
@@ -568,7 +606,30 @@ sub process_arguments(){
568 exit $ERRORS{'UNKNOWN'}; 606 exit $ERRORS{'UNKNOWN'};
569 } 607 }
570 }else{ 608 }else{
571 $mailq = 'sendmail' ; 609 if (defined $utils::PATH_TO_QMAIL_QSTAT
610 && -x $utils::PATH_TO_QMAIL_QSTAT)
611 {
612 $mailq = 'qmail';
613 }
614 elsif (-d '/var/lib/postfix' || -d '/var/local/lib/postfix'
615 || -e '/usr/sbin/postfix' || -e '/usr/local/sbin/postfix')
616 {
617 $mailq = 'postfix';
618 }
619 elsif (-d '/usr/lib/exim4' || -d '/usr/local/lib/exim4'
620 || -e '/usr/sbin/exim' || -e '/usr/local/sbin/exim')
621 {
622 $mailq = 'exim';
623 }
624 elsif (-d '/usr/lib/nullmailer' || -d '/usr/local/lib/nullmailer'
625 || -e '/usr/sbin/nullmailer-send'
626 || -e '/usr/local/sbin/nullmailer-send')
627 {
628 $mailq = 'nullmailer';
629 }
630 else {
631 $mailq = 'sendmail';
632 }
572 } 633 }
573 634
574 return $ERRORS{'OK'}; 635 return $ERRORS{'OK'};
@@ -591,7 +652,7 @@ sub print_help () {
591 print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; 652 print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n";
592 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; 653 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n";
593 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; 654 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
594 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim ] (default = sendmail)\n"; 655 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
595 print "-h (--help)\n"; 656 print "-h (--help)\n";
596 print "-V (--version)\n"; 657 print "-V (--version)\n";
597 print "-v (--verbose) = debugging output\n"; 658 print "-v (--verbose) = debugging output\n";
@@ -599,6 +660,8 @@ sub print_help () {
599 print "Note: -w and -c are required arguments. -W and -C are optional.\n"; 660 print "Note: -w and -c are required arguments. -W and -C are optional.\n";
600 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; 661 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n";
601 print " -W and -C are applied message not yet preproccessed. (qmail)\n"; 662 print " -W and -C are applied message not yet preproccessed. (qmail)\n";
663 print " This plugin tries to autodetect which mailserver you are running,\n";
664 print " you can override the autodetection with -M.\n";
602 print " This plugin uses the system mailq command (sendmail) or qmail-stat (qmail)\n"; 665 print " This plugin uses the system mailq command (sendmail) or qmail-stat (qmail)\n";
603 print " to look at the queues. Mailq can usually only be accessed by root or \n"; 666 print " to look at the queues. Mailq can usually only be accessed by root or \n";
604 print " a TrustedUser. You will have to set appropriate permissions for the plugin to work.\n"; 667 print " a TrustedUser. You will have to set appropriate permissions for the plugin to work.\n";