diff options
Diffstat (limited to 'plugins-scripts/check_mailq.pl')
-rwxr-xr-x | plugins-scripts/check_mailq.pl | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d3..27073d3c 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 | ||
@@ -531,9 +537,9 @@ elsif ( $mailq eq "nullmailer" ) { | |||
531 | } | 537 | } |
532 | 538 | ||
533 | while (<MAILQ>) { | 539 | while (<MAILQ>) { |
534 | #2006-06-22 16:00:00 282 bytes | 540 | #2022-08-25 01:30:40 502 bytes from <user@example.com> |
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 (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) { |
537 | $msg_q++ ; | 543 | $msg_q++ ; |
538 | } | 544 | } |
539 | } | 545 | } |
@@ -561,14 +567,17 @@ exit $state; | |||
561 | 567 | ||
562 | sub process_arguments(){ | 568 | sub process_arguments(){ |
563 | GetOptions | 569 | GetOptions |
564 | ("V" => \$opt_V, "version" => \$opt_V, | 570 | ("V" => \$opt_V, "version" => \$opt_V, |
565 | "v" => \$opt_v, "verbose" => \$opt_v, | 571 | "v" => \$opt_v, "verbose" => \$opt_v, |
566 | "h" => \$opt_h, "help" => \$opt_h, | 572 | "h" => \$opt_h, "help" => \$opt_h, |
567 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) | 573 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) |
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 |
576 | "W=i" => \$opt_W, "warning-domain=i" => \$opt_W, # Warning if above this number | ||
577 | "C=i" => \$opt_C, "critical-domain=i" => \$opt_C, # Critical if above this number | ||
570 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | 578 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, |
571 | "s" => \$opt_s, "sudo" => \$opt_s | 579 | "s" => \$opt_s, "sudo" => \$opt_s, |
580 | "d:s" => \$opt_d, "configdir:s" => \$opt_d, | ||
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,14 +671,15 @@ 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 (--warning-domain) = 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 (--critical-domain) = 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"; |
673 | print "\n\n"; | 683 | print "\n\n"; |
674 | print "Note: -w and -c are required arguments. -W and -C are optional.\n"; | 684 | print "Note: -w and -c are required arguments. -W and -C are optional.\n"; |
675 | print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; | 685 | print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; |