summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2021-12-02 15:16:57 (GMT)
committerGitHub <noreply@github.com>2021-12-02 15:16:57 (GMT)
commited7cdf82a42f16532801ea4f118870ce9a130fcf (patch)
treecf986a4b2e48702284d96e04bc310dd86ebdf68d
parent1a3a715702a5b6709fed2a1eb53ec644c9968057 (diff)
parent8df8460c6cd5c926990fddc1659e0f4194848473 (diff)
downloadmonitoring-plugins-ed7cdf8.tar.gz
Merge pull request #1490 from leeclemens/mailq-add-config-dir
check_mailq: Add mailq -C option for config dir or config file
-rwxr-xr-xplugins-scripts/check_mailq.pl24
1 files changed, 16 insertions, 8 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index c548608..3914f4a 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -28,9 +28,9 @@
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 $opt_s 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 utils qw(%ERRORS &print_revision &support &usage ); 36use 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
53Getopt::Long::Configure('bundling'); 55Getopt::Long::Configure('bundling');
@@ -68,6 +70,10 @@ if ($opt_s) {
68 $sudo = ""; 70 $sudo = "";
69} 71}
70 72
73if ($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
@@ -569,6 +575,7 @@ sub process_arguments(){
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 "W=i" => \$opt_W, # warning if above this number 579 "W=i" => \$opt_W, # warning if above this number
573 "C=i" => \$opt_C, # critical if above this number 580 "C=i" => \$opt_C, # critical if above this number
574 ); 581 );
@@ -651,7 +658,7 @@ sub process_arguments(){
651} 658}
652 659
653sub print_usage () { 660sub print_usage () {
654 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n"; 661 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n";
655} 662}
656 663
657sub print_help () { 664sub print_help () {
@@ -669,6 +676,7 @@ sub print_help () {
669 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; 676 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
670 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 677 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
671 print "-s (--sudo) = Use sudo to call the mailq command\n"; 678 print "-s (--sudo) = Use sudo to call the mailq command\n";
679 print "-d (--configdir) = Config file or directory\n";
672 print "-h (--help)\n"; 680 print "-h (--help)\n";
673 print "-V (--version)\n"; 681 print "-V (--version)\n";
674 print "-v (--verbose) = debugging output\n"; 682 print "-v (--verbose) = debugging output\n";