diff options
author | Lee Clemens <java@leeclemens.net> | 2017-05-16 11:23:43 -0400 |
---|---|---|
committer | Lee Clemens <java@leeclemens.net> | 2017-05-16 11:29:01 -0400 |
commit | 6246b8f1830e8a375bc656deafd28aab715b4fd9 (patch) | |
tree | 9fe9b2e1dfbce1010fa7870a71ba4e214a7df19d | |
parent | b3d39e605ef7ce7da056721c4e2e140966be3530 (diff) | |
download | monitoring-plugins-6246b8f1830e8a375bc656deafd28aab715b4fd9.tar.gz |
Add mailq -C option for config dir or config file
New variable, mailq_args, is appended for postfix mta mailq commands
Fixes #1489
-rwxr-xr-x | plugins-scripts/check_mailq.pl | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d3..9ef292e7 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
@@ -28,9 +28,9 @@ | |||
28 | use POSIX; | 28 | use POSIX; |
29 | use strict; | 29 | use strict; |
30 | use Getopt::Long; | 30 | use Getopt::Long; |
31 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s | 31 | use 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); |
34 | use FindBin; | 34 | use FindBin; |
35 | use lib "$FindBin::Bin"; | 35 | use lib "$FindBin::Bin"; |
36 | use utils qw(%ERRORS &print_revision &support &usage ); | 36 | use utils qw(%ERRORS &print_revision &support &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 | ||
53 | Getopt::Long::Configure('bundling'); | 55 | Getopt::Long::Configure('bundling'); |
@@ -68,6 +70,10 @@ if ($opt_s) { | |||
68 | $sudo = ""; | 70 | $sudo = ""; |
69 | } | 71 | } |
70 | 72 | ||
73 | if ($opt_d) { | ||
74 | $mailq_args = $mailq_args . ' -C ' . $opt_d; | ||
75 | } | ||
76 | |||
71 | $SIG{'ALRM'} = sub { | 77 | $SIG{'ALRM'} = sub { |
72 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); | 78 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); |
73 | exit $ERRORS{"WARNING"}; | 79 | exit $ERRORS{"WARNING"}; |
@@ -309,8 +315,8 @@ elsif ( $mailq eq "postfix" ) { | |||
309 | 315 | ||
310 | ## open mailq | 316 | ## open mailq |
311 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 317 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
312 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { | 318 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) { |
313 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 319 | print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n"; |
314 | exit $ERRORS{'UNKNOWN'}; | 320 | exit $ERRORS{'UNKNOWN'}; |
315 | } | 321 | } |
316 | }elsif( defined $utils::PATH_TO_MAILQ){ | 322 | }elsif( defined $utils::PATH_TO_MAILQ){ |
@@ -330,7 +336,7 @@ elsif ( $mailq eq "postfix" ) { | |||
330 | close MAILQ; | 336 | close MAILQ; |
331 | 337 | ||
332 | if ( $? ) { | 338 | if ( $? ) { |
333 | 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",$/; |
334 | exit $ERRORS{CRITICAL}; | 340 | exit $ERRORS{CRITICAL}; |
335 | } | 341 | } |
336 | 342 | ||
@@ -343,7 +349,7 @@ elsif ( $mailq eq "postfix" ) { | |||
343 | }elsif ($lines[0]=~/Mail queue is empty/) { | 349 | }elsif ($lines[0]=~/Mail queue is empty/) { |
344 | $msg_q = 0; | 350 | $msg_q = 0; |
345 | }else{ | 351 | }else{ |
346 | print "Couldn't match $utils::PATH_TO_MAILQ output\n"; | 352 | print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n"; |
347 | exit $ERRORS{'UNKNOWN'}; | 353 | exit $ERRORS{'UNKNOWN'}; |
348 | } | 354 | } |
349 | 355 | ||
@@ -568,7 +574,8 @@ sub process_arguments(){ | |||
568 | "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 |
569 | "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 |
570 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | 576 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, |
571 | "s" => \$opt_s, "sudo" => \$opt_s | 577 | "s" => \$opt_s, "sudo" => \$opt_s, |
578 | "d:s" => \$opt_d, "configdir:s" => \$opt_d | ||
572 | ); | 579 | ); |
573 | 580 | ||
574 | if ($opt_V) { | 581 | if ($opt_V) { |
@@ -649,7 +656,7 @@ sub process_arguments(){ | |||
649 | } | 656 | } |
650 | 657 | ||
651 | sub print_usage () { | 658 | sub print_usage () { |
652 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n"; | 659 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n"; |
653 | } | 660 | } |
654 | 661 | ||
655 | sub print_help () { | 662 | sub print_help () { |
@@ -667,6 +674,7 @@ sub print_help () { | |||
667 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 674 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
668 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; | 675 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; |
669 | print "-s (--sudo) = Use sudo to call the mailq command\n"; | 676 | print "-s (--sudo) = Use sudo to call the mailq command\n"; |
677 | print "-d (--configdir) = Config file or directory\n"; | ||
670 | print "-h (--help)\n"; | 678 | print "-h (--help)\n"; |
671 | print "-V (--version)\n"; | 679 | print "-V (--version)\n"; |
672 | print "-v (--verbose) = debugging output\n"; | 680 | print "-v (--verbose) = debugging output\n"; |