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.pl61
1 files changed, 42 insertions, 19 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 0e8100d0..3914f4a7 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -28,14 +28,14 @@
28use POSIX; 28use POSIX;
29use strict; 29use strict;
30use Getopt::Long; 30use 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 $opt_s $opt_d
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 $mailq_args
33 %srcdomains %dstdomains); 33 @lines %srcdomains %dstdomains);
34use FindBin; 34use FindBin;
35use lib "$FindBin::Bin"; 35use lib "$FindBin::Bin";
36use lib '@libexecdir@';
37use utils qw(%ERRORS &print_revision &support &usage ); 36use utils qw(%ERRORS &print_revision &support &usage );
38 37
38my ($sudo);
39 39
40sub print_help (); 40sub print_help ();
41sub print_usage (); 41sub print_usage ();
@@ -48,6 +48,8 @@ $PROGNAME = "check_mailq";
48$mailq = 'sendmail'; # default 48$mailq = 'sendmail'; # default
49$msg_q = 0 ; 49$msg_q = 0 ;
50$msg_p = 0 ; 50$msg_p = 0 ;
51# If appended, must start with a space
52$mailq_args = '' ;
51$state = $ERRORS{'UNKNOWN'}; 53$state = $ERRORS{'UNKNOWN'};
52 54
53Getopt::Long::Configure('bundling'); 55Getopt::Long::Configure('bundling');
@@ -57,6 +59,21 @@ if ($status){
57 exit $ERRORS{"UNKNOWN"}; 59 exit $ERRORS{"UNKNOWN"};
58} 60}
59 61
62if ($opt_s) {
63 if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) {
64 $sudo = $utils::PATH_TO_SUDO;
65 } else {
66 print "ERROR: Cannot execute sudo\n";
67 exit $ERRORS{'UNKNOWN'};
68 }
69} else {
70 $sudo = "";
71}
72
73if ($opt_d) {
74 $mailq_args = $mailq_args . ' -C ' . $opt_d;
75}
76
60$SIG{'ALRM'} = sub { 77$SIG{'ALRM'} = sub {
61 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); 78 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
62 exit $ERRORS{"WARNING"}; 79 exit $ERRORS{"WARNING"};
@@ -69,7 +86,7 @@ if ($mailq eq "sendmail") {
69 86
70 ## open mailq 87 ## open mailq
71 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 88 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
72 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 89 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
73 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 90 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
74 exit $ERRORS{'UNKNOWN'}; 91 exit $ERRORS{'UNKNOWN'};
75 } 92 }
@@ -298,8 +315,8 @@ elsif ( $mailq eq "postfix" ) {
298 315
299 ## open mailq 316 ## open mailq
300 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 317 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
301 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 318 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) {
302 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 319 print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n";
303 exit $ERRORS{'UNKNOWN'}; 320 exit $ERRORS{'UNKNOWN'};
304 } 321 }
305 }elsif( defined $utils::PATH_TO_MAILQ){ 322 }elsif( defined $utils::PATH_TO_MAILQ){
@@ -319,7 +336,7 @@ elsif ( $mailq eq "postfix" ) {
319 close MAILQ; 336 close MAILQ;
320 337
321 if ( $? ) { 338 if ( $? ) {
322 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; 339 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/;
323 exit $ERRORS{CRITICAL}; 340 exit $ERRORS{CRITICAL};
324 } 341 }
325 342
@@ -332,7 +349,7 @@ elsif ( $mailq eq "postfix" ) {
332 }elsif ($lines[0]=~/Mail queue is empty/) { 349 }elsif ($lines[0]=~/Mail queue is empty/) {
333 $msg_q = 0; 350 $msg_q = 0;
334 }else{ 351 }else{
335 print "Couldn't match $utils::PATH_TO_MAILQ output\n"; 352 print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n";
336 exit $ERRORS{'UNKNOWN'}; 353 exit $ERRORS{'UNKNOWN'};
337 } 354 }
338 355
@@ -380,7 +397,7 @@ elsif ( $mailq eq "qmail" ) {
380 397
381 # open qmail-qstat 398 # open qmail-qstat
382 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { 399 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) {
383 if (! open (MAILQ, "$utils::PATH_TO_QMAIL_QSTAT | " ) ) { 400 if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) {
384 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; 401 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
385 exit $ERRORS{'UNKNOWN'}; 402 exit $ERRORS{'UNKNOWN'};
386 } 403 }
@@ -462,7 +479,7 @@ elsif ( $mailq eq "qmail" ) {
462elsif ( $mailq eq "exim" ) { 479elsif ( $mailq eq "exim" ) {
463 ## open mailq 480 ## open mailq
464 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 481 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
465 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 482 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
466 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 483 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
467 exit $ERRORS{'UNKNOWN'}; 484 exit $ERRORS{'UNKNOWN'};
468 } 485 }
@@ -505,7 +522,7 @@ elsif ( $mailq eq "exim" ) {
505elsif ( $mailq eq "nullmailer" ) { 522elsif ( $mailq eq "nullmailer" ) {
506 ## open mailq 523 ## open mailq
507 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 524 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
508 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 525 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
509 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 526 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
510 exit $ERRORS{'UNKNOWN'}; 527 exit $ERRORS{'UNKNOWN'};
511 } 528 }
@@ -522,7 +539,7 @@ elsif ( $mailq eq "nullmailer" ) {
522 while (<MAILQ>) { 539 while (<MAILQ>) {
523 #2006-06-22 16:00:00 282 bytes 540 #2006-06-22 16:00:00 282 bytes
524 541
525 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$/) { 542 if (/^[1-9][0-9]*-[01][0-9]-[0-3][0-9]\s[0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]\s+[0-9]+\sbytes/) {
526 $msg_q++ ; 543 $msg_q++ ;
527 } 544 }
528 } 545 }
@@ -556,17 +573,21 @@ sub process_arguments(){
556 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) 573 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail)
557 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number 574 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number
558 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number 575 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number
559 "t=i" => \$opt_t, "timeout=i" => \$opt_t 576 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
577 "s" => \$opt_s, "sudo" => \$opt_s,
578 "d:s" => \$opt_d, "configdir:s" => \$opt_d,
579 "W=i" => \$opt_W, # warning if above this number
580 "C=i" => \$opt_C, # critical if above this number
560 ); 581 );
561 582
562 if ($opt_V) { 583 if ($opt_V) {
563 print_revision($PROGNAME,'@NP_VERSION@'); 584 print_revision($PROGNAME,'@NP_VERSION@');
564 exit $ERRORS{'OK'}; 585 exit $ERRORS{'UNKNOWN'};
565 } 586 }
566 587
567 if ($opt_h) { 588 if ($opt_h) {
568 print_help(); 589 print_help();
569 exit $ERRORS{'OK'}; 590 exit $ERRORS{'UNKNOWN'};
570 } 591 }
571 592
572 if (defined $opt_v ){ 593 if (defined $opt_v ){
@@ -637,7 +658,7 @@ sub process_arguments(){
637} 658}
638 659
639sub print_usage () { 660sub print_usage () {
640 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n"; 661 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n";
641} 662}
642 663
643sub print_help () { 664sub print_help () {
@@ -650,10 +671,12 @@ sub print_help () {
650 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; 671 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n";
651 print "-w (--warning) = Min. number of messages in queue to generate warning\n"; 672 print "-w (--warning) = Min. number of messages in queue to generate warning\n";
652 print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; 673 print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n";
653 print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; 674 print "-W = Min. number of messages for same domain in queue to generate warning\n";
654 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; 675 print "-C = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n";
655 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; 676 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
656 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 677 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
678 print "-s (--sudo) = Use sudo to call the mailq command\n";
679 print "-d (--configdir) = Config file or directory\n";
657 print "-h (--help)\n"; 680 print "-h (--help)\n";
658 print "-V (--version)\n"; 681 print "-V (--version)\n";
659 print "-v (--verbose) = debugging output\n"; 682 print "-v (--verbose) = debugging output\n";