From 6246b8f1830e8a375bc656deafd28aab715b4fd9 Mon Sep 17 00:00:00 2001 From: Lee Clemens Date: Tue, 16 May 2017 11:23:43 -0400 Subject: Add mailq -C option for config dir or config file New variable, mailq_args, is appended for postfix mta mailq commands Fixes #1489 diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 32f498d..9ef292e 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'}; } @@ -568,7 +574,8 @@ 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 ); if ($opt_V) { @@ -649,7 +656,7 @@ sub process_arguments(){ } sub print_usage () { - print "Usage: $PROGNAME -w -c [-W ] [-C ] [-M ] [-t ] [-s] [-v]\n"; + print "Usage: $PROGNAME -w -c [-W ] [-C ] [-M ] [-t ] [-s] [-d ] [-v]\n"; } sub print_help () { @@ -667,6 +674,7 @@ sub print_help () { 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"; -- cgit v0.10-9-g596f From 8df8460c6cd5c926990fddc1659e0f4194848473 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 2 Dec 2021 15:26:31 +0100 Subject: Fix syntax error resulting from merging diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 4bc9487..3914f4a 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl @@ -575,7 +575,7 @@ sub process_arguments(){ "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, - "d:s" => \$opt_d, "configdir:s" => \$opt_d + "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 ); -- cgit v0.10-9-g596f