diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2021-12-02 15:42:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-02 15:42:05 (GMT) |
commit | 911e44045d7291f5ede22739fd176ef55dd3de4a (patch) | |
tree | cf36b95a4a964b03d6ecf75770ced2cb3a2ac3a9 /plugins-scripts/check_mailq.pl | |
parent | 8294af907bd8482a86df749f562b7ec09e3faeed (diff) | |
parent | ed7cdf82a42f16532801ea4f118870ce9a130fcf (diff) | |
download | monitoring-plugins-911e44045d7291f5ede22739fd176ef55dd3de4a.tar.gz |
Merge branch 'master' into fix/shellcheckrefs/pull/1459/head
Diffstat (limited to 'plugins-scripts/check_mailq.pl')
-rwxr-xr-x | plugins-scripts/check_mailq.pl | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d..3914f4a 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 | ||
@@ -533,7 +539,7 @@ elsif ( $mailq eq "nullmailer" ) { | |||
533 | while (<MAILQ>) { | 539 | while (<MAILQ>) { |
534 | #2006-06-22 16:00:00 282 bytes | 540 | #2006-06-22 16:00:00 282 bytes |
535 | 541 | ||
536 | 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/) { |
537 | $msg_q++ ; | 543 | $msg_q++ ; |
538 | } | 544 | } |
539 | } | 545 | } |
@@ -568,7 +574,10 @@ 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, | ||
579 | "W=i" => \$opt_W, # warning if above this number | ||
580 | "C=i" => \$opt_C, # critical if above this number | ||
572 | ); | 581 | ); |
573 | 582 | ||
574 | if ($opt_V) { | 583 | if ($opt_V) { |
@@ -649,7 +658,7 @@ sub process_arguments(){ | |||
649 | } | 658 | } |
650 | 659 | ||
651 | sub print_usage () { | 660 | sub print_usage () { |
652 | 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"; |
653 | } | 662 | } |
654 | 663 | ||
655 | sub print_help () { | 664 | sub print_help () { |
@@ -662,11 +671,12 @@ sub print_help () { | |||
662 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; | 671 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; |
663 | 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"; |
664 | 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"; |
665 | 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"; |
666 | 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"; |
667 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 676 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
668 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; | 677 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; |
669 | 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"; | ||
670 | print "-h (--help)\n"; | 680 | print "-h (--help)\n"; |
671 | print "-V (--version)\n"; | 681 | print "-V (--version)\n"; |
672 | print "-v (--verbose) = debugging output\n"; | 682 | print "-v (--verbose) = debugging output\n"; |