summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_mailq.pl
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2014-12-02 20:13:38 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2014-12-02 20:13:38 (GMT)
commit8235fd0aef2945e0d638fba3493134588d085d5a (patch)
treeaafe5c7cf840fe013ca423445cc88bb5f8b1bc74 /plugins-scripts/check_mailq.pl
parent04e0a182aeb5defaf6b39cbbd8d9c87491c4f1e4 (diff)
downloadmonitoring-plugins-8235fd0aef2945e0d638fba3493134588d085d5a.tar.gz
check_mailq: Add sudo support
This addition is based on a patch contributed by Christopher Schultz. Closes #1099. Closes #1171.
Diffstat (limited to 'plugins-scripts/check_mailq.pl')
-rwxr-xr-xplugins-scripts/check_mailq.pl30
1 files changed, 22 insertions, 8 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 0e8100d..417c4bf 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -28,7 +28,7 @@
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;
@@ -36,6 +36,7 @@ use lib "$FindBin::Bin";
36use lib '@libexecdir@'; 36use lib '@libexecdir@';
37use utils qw(%ERRORS &print_revision &support &usage ); 37use utils qw(%ERRORS &print_revision &support &usage );
38 38
39my ($sudo);
39 40
40sub print_help (); 41sub print_help ();
41sub print_usage (); 42sub print_usage ();
@@ -57,6 +58,17 @@ if ($status){
57 exit $ERRORS{"UNKNOWN"}; 58 exit $ERRORS{"UNKNOWN"};
58} 59}
59 60
61if ($opt_s) {
62 if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) {
63 $sudo = $utils::PATH_TO_SUDO;
64 } else {
65 print "ERROR: Cannot execute sudo\n";
66 exit $ERRORS{'UNKNOWN'};
67 }
68} else {
69 $sudo = "";
70}
71
60$SIG{'ALRM'} = sub { 72$SIG{'ALRM'} = sub {
61 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); 73 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
62 exit $ERRORS{"WARNING"}; 74 exit $ERRORS{"WARNING"};
@@ -69,7 +81,7 @@ if ($mailq eq "sendmail") {
69 81
70 ## open mailq 82 ## open mailq
71 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 83 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
72 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 84 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
73 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 85 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
74 exit $ERRORS{'UNKNOWN'}; 86 exit $ERRORS{'UNKNOWN'};
75 } 87 }
@@ -298,7 +310,7 @@ elsif ( $mailq eq "postfix" ) {
298 310
299 ## open mailq 311 ## open mailq
300 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 312 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
301 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 313 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
302 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 314 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
303 exit $ERRORS{'UNKNOWN'}; 315 exit $ERRORS{'UNKNOWN'};
304 } 316 }
@@ -380,7 +392,7 @@ elsif ( $mailq eq "qmail" ) {
380 392
381 # open qmail-qstat 393 # open qmail-qstat
382 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { 394 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) {
383 if (! open (MAILQ, "$utils::PATH_TO_QMAIL_QSTAT | " ) ) { 395 if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) {
384 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; 396 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
385 exit $ERRORS{'UNKNOWN'}; 397 exit $ERRORS{'UNKNOWN'};
386 } 398 }
@@ -462,7 +474,7 @@ elsif ( $mailq eq "qmail" ) {
462elsif ( $mailq eq "exim" ) { 474elsif ( $mailq eq "exim" ) {
463 ## open mailq 475 ## open mailq
464 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 476 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
465 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 477 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
466 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 478 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
467 exit $ERRORS{'UNKNOWN'}; 479 exit $ERRORS{'UNKNOWN'};
468 } 480 }
@@ -505,7 +517,7 @@ elsif ( $mailq eq "exim" ) {
505elsif ( $mailq eq "nullmailer" ) { 517elsif ( $mailq eq "nullmailer" ) {
506 ## open mailq 518 ## open mailq
507 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 519 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
508 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { 520 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
509 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 521 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
510 exit $ERRORS{'UNKNOWN'}; 522 exit $ERRORS{'UNKNOWN'};
511 } 523 }
@@ -556,7 +568,8 @@ sub process_arguments(){
556 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) 568 "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 569 "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 570 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number
559 "t=i" => \$opt_t, "timeout=i" => \$opt_t 571 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
572 "s" => \$opt_s, "sudo" => \$opt_s
560 ); 573 );
561 574
562 if ($opt_V) { 575 if ($opt_V) {
@@ -637,7 +650,7 @@ sub process_arguments(){
637} 650}
638 651
639sub print_usage () { 652sub print_usage () {
640 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n"; 653 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n";
641} 654}
642 655
643sub print_help () { 656sub print_help () {
@@ -654,6 +667,7 @@ sub print_help () {
654 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; 667 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"; 668 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
656 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 669 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
670 print "-s (--sudo) = Use sudo to call the mailq command\n";
657 print "-h (--help)\n"; 671 print "-h (--help)\n";
658 print "-V (--version)\n"; 672 print "-V (--version)\n";
659 print "-v (--verbose) = debugging output\n"; 673 print "-v (--verbose) = debugging output\n";