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.pl35
1 files changed, 24 insertions, 11 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 0e8100d..32f498d 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
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 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 ();
@@ -57,6 +57,17 @@ if ($status){
57 exit $ERRORS{"UNKNOWN"}; 57 exit $ERRORS{"UNKNOWN"};
58} 58}
59 59
60if ($opt_s) {
61 if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) {
62 $sudo = $utils::PATH_TO_SUDO;
63 } else {
64 print "ERROR: Cannot execute sudo\n";
65 exit $ERRORS{'UNKNOWN'};
66 }
67} else {
68 $sudo = "";
69}
70
60$SIG{'ALRM'} = sub { 71$SIG{'ALRM'} = sub {
61 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); 72 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
62 exit $ERRORS{"WARNING"}; 73 exit $ERRORS{"WARNING"};
@@ -69,7 +80,7 @@ if ($mailq eq "sendmail") {
69 80
70 ## open mailq 81 ## open mailq
71 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 82 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
72 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 83 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
73 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 84 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
74 exit $ERRORS{'UNKNOWN'}; 85 exit $ERRORS{'UNKNOWN'};
75 } 86 }
@@ -298,7 +309,7 @@ elsif ( $mailq eq "postfix" ) {
298 309
299 ## open mailq 310 ## open mailq
300 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 311 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
301 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 312 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
302 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 313 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
303 exit $ERRORS{'UNKNOWN'}; 314 exit $ERRORS{'UNKNOWN'};
304 } 315 }
@@ -380,7 +391,7 @@ elsif ( $mailq eq "qmail" ) {
380 391
381 # open qmail-qstat 392 # open qmail-qstat
382 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { 393 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) {
383 if (! open (MAILQ, "$utils::PATH_TO_QMAIL_QSTAT | " ) ) { 394 if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) {
384 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; 395 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
385 exit $ERRORS{'UNKNOWN'}; 396 exit $ERRORS{'UNKNOWN'};
386 } 397 }
@@ -462,7 +473,7 @@ elsif ( $mailq eq "qmail" ) {
462elsif ( $mailq eq "exim" ) { 473elsif ( $mailq eq "exim" ) {
463 ## open mailq 474 ## open mailq
464 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 475 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
465 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 476 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
466 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 477 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
467 exit $ERRORS{'UNKNOWN'}; 478 exit $ERRORS{'UNKNOWN'};
468 } 479 }
@@ -505,7 +516,7 @@ elsif ( $mailq eq "exim" ) {
505elsif ( $mailq eq "nullmailer" ) { 516elsif ( $mailq eq "nullmailer" ) {
506 ## open mailq 517 ## open mailq
507 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 518 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
508 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 519 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
509 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 520 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
510 exit $ERRORS{'UNKNOWN'}; 521 exit $ERRORS{'UNKNOWN'};
511 } 522 }
@@ -556,17 +567,18 @@ sub process_arguments(){
556 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) 567 "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 568 "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 569 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number
559 "t=i" => \$opt_t, "timeout=i" => \$opt_t 570 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
571 "s" => \$opt_s, "sudo" => \$opt_s
560 ); 572 );
561 573
562 if ($opt_V) { 574 if ($opt_V) {
563 print_revision($PROGNAME,'@NP_VERSION@'); 575 print_revision($PROGNAME,'@NP_VERSION@');
564 exit $ERRORS{'OK'}; 576 exit $ERRORS{'UNKNOWN'};
565 } 577 }
566 578
567 if ($opt_h) { 579 if ($opt_h) {
568 print_help(); 580 print_help();
569 exit $ERRORS{'OK'}; 581 exit $ERRORS{'UNKNOWN'};
570 } 582 }
571 583
572 if (defined $opt_v ){ 584 if (defined $opt_v ){
@@ -637,7 +649,7 @@ sub process_arguments(){
637} 649}
638 650
639sub print_usage () { 651sub print_usage () {
640 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n"; 652 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n";
641} 653}
642 654
643sub print_help () { 655sub print_help () {
@@ -654,6 +666,7 @@ sub print_help () {
654 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; 666 print "-C (--Critical) = 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"; 667 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
656 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 668 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
669 print "-s (--sudo) = Use sudo to call the mailq command\n";
657 print "-h (--help)\n"; 670 print "-h (--help)\n";
658 print "-V (--version)\n"; 671 print "-V (--version)\n";
659 print "-v (--verbose) = debugging output\n"; 672 print "-v (--verbose) = debugging output\n";