diff options
author | Lorenz <12514511+RincewindsHat@users.noreply.github.com> | 2022-01-03 13:48:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-03 13:48:39 +0100 |
commit | 2714df42fd27ec377228a102acff3744d6bff86d (patch) | |
tree | 3098fa3d9be4826e5da9d1df39ecf6b42bf3570b /plugins-scripts/check_mailq.pl | |
parent | 11af74de386ba7c02d5d0e53f2500b5029a4537d (diff) | |
parent | 78a999edd4dd3305ef8fa3e06c43f6a893fb6fea (diff) | |
download | monitoring-plugins-2714df42fd27ec377228a102acff3744d6bff86d.tar.gz |
Merge branch 'master' into master
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 32f498d3..3914f4a7 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl @@ -28,9 +28,9 @@ use POSIX; use strict; use Getopt::Long; -use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s - $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines - %srcdomains %dstdomains); +use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s $opt_d + $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq $mailq_args + @lines %srcdomains %dstdomains); use FindBin; use lib "$FindBin::Bin"; use utils qw(%ERRORS &print_revision &support &usage ); @@ -48,6 +48,8 @@ $PROGNAME = "check_mailq"; $mailq = 'sendmail'; # default $msg_q = 0 ; $msg_p = 0 ; +# If appended, must start with a space +$mailq_args = '' ; $state = $ERRORS{'UNKNOWN'}; Getopt::Long::Configure('bundling'); @@ -68,6 +70,10 @@ if ($opt_s) { $sudo = ""; } +if ($opt_d) { + $mailq_args = $mailq_args . ' -C ' . $opt_d; +} + $SIG{'ALRM'} = sub { print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); exit $ERRORS{"WARNING"}; @@ -309,8 +315,8 @@ elsif ( $mailq eq "postfix" ) { ## open mailq if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { - if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { - print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; + if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) { + print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n"; exit $ERRORS{'UNKNOWN'}; } }elsif( defined $utils::PATH_TO_MAILQ){ @@ -330,7 +336,7 @@ elsif ( $mailq eq "postfix" ) { close MAILQ; if ( $? ) { - print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; + print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/; exit $ERRORS{CRITICAL}; } @@ -343,7 +349,7 @@ elsif ( $mailq eq "postfix" ) { }elsif ($lines[0]=~/Mail queue is empty/) { $msg_q = 0; }else{ - print "Couldn't match $utils::PATH_TO_MAILQ output\n"; + print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n"; exit $ERRORS{'UNKNOWN'}; } @@ -533,7 +539,7 @@ elsif ( $mailq eq "nullmailer" ) { while (<MAILQ>) { #2006-06-22 16:00:00 282 bytes - 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$/) { + 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/) { $msg_q++ ; } } @@ -568,7 +574,10 @@ sub process_arguments(){ "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number "t=i" => \$opt_t, "timeout=i" => \$opt_t, - "s" => \$opt_s, "sudo" => \$opt_s + "s" => \$opt_s, "sudo" => \$opt_s, + "d:s" => \$opt_d, "configdir:s" => \$opt_d, + "W=i" => \$opt_W, # warning if above this number + "C=i" => \$opt_C, # critical if above this number ); if ($opt_V) { @@ -649,7 +658,7 @@ sub process_arguments(){ } sub print_usage () { - print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n"; + print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n"; } sub print_help () { @@ -662,11 +671,12 @@ sub print_help () { print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; print "-w (--warning) = Min. number of messages in queue to generate warning\n"; print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; - print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n"; - print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; + print "-W = Min. number of messages for same domain in queue to generate warning\n"; + print "-C = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; print "-s (--sudo) = Use sudo to call the mailq command\n"; + print "-d (--configdir) = Config file or directory\n"; print "-h (--help)\n"; print "-V (--version)\n"; print "-v (--verbose) = debugging output\n"; |