diff options
| author | Holger Weiss <holger@zedat.fu-berlin.de> | 2014-12-02 21:13:38 +0100 |
|---|---|---|
| committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2014-12-02 21:13:38 +0100 |
| commit | 8235fd0aef2945e0d638fba3493134588d085d5a (patch) | |
| tree | aafe5c7cf840fe013ca423445cc88bb5f8b1bc74 | |
| parent | 04e0a182aeb5defaf6b39cbbd8d9c87491c4f1e4 (diff) | |
| download | monitoring-plugins-8235fd0aef2945e0d638fba3493134588d085d5a.tar.gz | |
check_mailq: Add sudo support
This addition is based on a patch contributed by Christopher Schultz.
Closes #1099.
Closes #1171.
| -rw-r--r-- | NEWS | 1 | ||||
| -rw-r--r-- | THANKS.in | 1 | ||||
| -rw-r--r-- | configure.ac | 10 | ||||
| -rwxr-xr-x | plugins-scripts/check_mailq.pl | 30 | ||||
| -rw-r--r-- | plugins-scripts/utils.pm.in | 1 |
5 files changed, 35 insertions, 8 deletions
| @@ -7,6 +7,7 @@ This file documents the major additions and syntax changes between releases. | |||
| 7 | New check_snmp "-N" option to specify SNMPv3 context name | 7 | New check_snmp "-N" option to specify SNMPv3 context name |
| 8 | New check_nt "-l" parameters: seconds|minutes|hours|days | 8 | New check_nt "-l" parameters: seconds|minutes|hours|days |
| 9 | Make sure check_disk won't hang on hanging (network) file systems | 9 | Make sure check_disk won't hang on hanging (network) file systems |
| 10 | New check_mailq -s option which tells the plugin to use sudo(8) | ||
| 10 | 11 | ||
| 11 | FIXES | 12 | FIXES |
| 12 | Let check_real terminate lines with CRLF when talking to the server, as | 13 | Let check_real terminate lines with CRLF when talking to the server, as |
| @@ -334,3 +334,4 @@ Simon Meggle | |||
| 334 | Jonas Genannt | 334 | Jonas Genannt |
| 335 | Nick Peelman | 335 | Nick Peelman |
| 336 | Sebastian Herbszt | 336 | Sebastian Herbszt |
| 337 | Christopher Schultz | ||
diff --git a/configure.ac b/configure.ac index fb8f9500..ce1728e3 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -1484,6 +1484,16 @@ else | |||
| 1484 | AC_MSG_WARN([Get ssh in order to make check_by_ssh plugin]) | 1484 | AC_MSG_WARN([Get ssh in order to make check_by_ssh plugin]) |
| 1485 | fi | 1485 | fi |
| 1486 | 1486 | ||
| 1487 | AC_PATH_PROG(PATH_TO_SUDO,sudo) | ||
| 1488 | AC_ARG_WITH(sudo_command, | ||
| 1489 | ACX_HELP_STRING([--with-sudo-command=PATH], | ||
| 1490 | [sets path to sudo]), PATH_TO_SUDO=$withval) | ||
| 1491 | if test -n "$PATH_TO_SUDO" | ||
| 1492 | then | ||
| 1493 | AC_DEFINE_UNQUOTED(PATH_TO_SUDO,"$PATH_TO_SUDO",[path to sudo]) | ||
| 1494 | else | ||
| 1495 | AC_MSG_WARN([Could not find sudo or eqivalent]) | ||
| 1496 | fi | ||
| 1487 | 1497 | ||
| 1488 | AC_PATH_PROG(PATH_TO_MAILQ,mailq) | 1498 | AC_PATH_PROG(PATH_TO_MAILQ,mailq) |
| 1489 | AC_ARG_WITH(mailq_command, | 1499 | AC_ARG_WITH(mailq_command, |
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 0e8100d0..417c4bf7 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
| @@ -28,7 +28,7 @@ | |||
| 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 | 31 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s |
| 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 @lines |
| 33 | %srcdomains %dstdomains); | 33 | %srcdomains %dstdomains); |
| 34 | use FindBin; | 34 | use FindBin; |
| @@ -36,6 +36,7 @@ use lib "$FindBin::Bin"; | |||
| 36 | use lib '@libexecdir@'; | 36 | use lib '@libexecdir@'; |
| 37 | use utils qw(%ERRORS &print_revision &support &usage ); | 37 | use utils qw(%ERRORS &print_revision &support &usage ); |
| 38 | 38 | ||
| 39 | my ($sudo); | ||
| 39 | 40 | ||
| 40 | sub print_help (); | 41 | sub print_help (); |
| 41 | sub print_usage (); | 42 | sub print_usage (); |
| @@ -57,6 +58,17 @@ if ($status){ | |||
| 57 | exit $ERRORS{"UNKNOWN"}; | 58 | exit $ERRORS{"UNKNOWN"}; |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 61 | if ($opt_s) { | ||
| 62 | if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) { | ||
| 63 | $sudo = $utils::PATH_TO_SUDO; | ||
| 64 | } else { | ||
| 65 | print "ERROR: Cannot execute sudo\n"; | ||
| 66 | exit $ERRORS{'UNKNOWN'}; | ||
| 67 | } | ||
| 68 | } else { | ||
| 69 | $sudo = ""; | ||
| 70 | } | ||
| 71 | |||
| 60 | $SIG{'ALRM'} = sub { | 72 | $SIG{'ALRM'} = sub { |
| 61 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); | 73 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); |
| 62 | exit $ERRORS{"WARNING"}; | 74 | exit $ERRORS{"WARNING"}; |
| @@ -69,7 +81,7 @@ if ($mailq eq "sendmail") { | |||
| 69 | 81 | ||
| 70 | ## open mailq | 82 | ## open mailq |
| 71 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 83 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
| 72 | if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { | 84 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
| 73 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 85 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
| 74 | exit $ERRORS{'UNKNOWN'}; | 86 | exit $ERRORS{'UNKNOWN'}; |
| 75 | } | 87 | } |
| @@ -298,7 +310,7 @@ elsif ( $mailq eq "postfix" ) { | |||
| 298 | 310 | ||
| 299 | ## open mailq | 311 | ## open mailq |
| 300 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 312 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
| 301 | if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { | 313 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
| 302 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 314 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
| 303 | exit $ERRORS{'UNKNOWN'}; | 315 | exit $ERRORS{'UNKNOWN'}; |
| 304 | } | 316 | } |
| @@ -380,7 +392,7 @@ elsif ( $mailq eq "qmail" ) { | |||
| 380 | 392 | ||
| 381 | # open qmail-qstat | 393 | # open qmail-qstat |
| 382 | if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { | 394 | if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { |
| 383 | if (! open (MAILQ, "$utils::PATH_TO_QMAIL_QSTAT | " ) ) { | 395 | if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) { |
| 384 | print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; | 396 | print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; |
| 385 | exit $ERRORS{'UNKNOWN'}; | 397 | exit $ERRORS{'UNKNOWN'}; |
| 386 | } | 398 | } |
| @@ -462,7 +474,7 @@ elsif ( $mailq eq "qmail" ) { | |||
| 462 | elsif ( $mailq eq "exim" ) { | 474 | elsif ( $mailq eq "exim" ) { |
| 463 | ## open mailq | 475 | ## open mailq |
| 464 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 476 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
| 465 | if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { | 477 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
| 466 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 478 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
| 467 | exit $ERRORS{'UNKNOWN'}; | 479 | exit $ERRORS{'UNKNOWN'}; |
| 468 | } | 480 | } |
| @@ -505,7 +517,7 @@ elsif ( $mailq eq "exim" ) { | |||
| 505 | elsif ( $mailq eq "nullmailer" ) { | 517 | elsif ( $mailq eq "nullmailer" ) { |
| 506 | ## open mailq | 518 | ## open mailq |
| 507 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 519 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
| 508 | if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { | 520 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
| 509 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 521 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
| 510 | exit $ERRORS{'UNKNOWN'}; | 522 | exit $ERRORS{'UNKNOWN'}; |
| 511 | } | 523 | } |
| @@ -556,7 +568,8 @@ sub process_arguments(){ | |||
| 556 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) | 568 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) |
| 557 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number | 569 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number |
| 558 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number | 570 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number |
| 559 | "t=i" => \$opt_t, "timeout=i" => \$opt_t | 571 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, |
| 572 | "s" => \$opt_s, "sudo" => \$opt_s | ||
| 560 | ); | 573 | ); |
| 561 | 574 | ||
| 562 | if ($opt_V) { | 575 | if ($opt_V) { |
| @@ -637,7 +650,7 @@ sub process_arguments(){ | |||
| 637 | } | 650 | } |
| 638 | 651 | ||
| 639 | sub print_usage () { | 652 | sub print_usage () { |
| 640 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n"; | 653 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n"; |
| 641 | } | 654 | } |
| 642 | 655 | ||
| 643 | sub print_help () { | 656 | sub print_help () { |
| @@ -654,6 +667,7 @@ sub print_help () { | |||
| 654 | print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; | 667 | print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; |
| 655 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 668 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
| 656 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; | 669 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; |
| 670 | print "-s (--sudo) = Use sudo to call the mailq command\n"; | ||
| 657 | print "-h (--help)\n"; | 671 | print "-h (--help)\n"; |
| 658 | print "-V (--version)\n"; | 672 | print "-V (--version)\n"; |
| 659 | print "-v (--verbose) = debugging output\n"; | 673 | print "-v (--verbose) = debugging output\n"; |
diff --git a/plugins-scripts/utils.pm.in b/plugins-scripts/utils.pm.in index 0f53243c..386831eb 100644 --- a/plugins-scripts/utils.pm.in +++ b/plugins-scripts/utils.pm.in | |||
| @@ -17,6 +17,7 @@ sub support(); | |||
| 17 | sub is_hostname; | 17 | sub is_hostname; |
| 18 | 18 | ||
| 19 | ## updated by autoconf | 19 | ## updated by autoconf |
| 20 | $PATH_TO_SUDO = "@PATH_TO_SUDO@"; | ||
| 20 | $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ; | 21 | $PATH_TO_RPCINFO = "@PATH_TO_RPCINFO@" ; |
| 21 | $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ; | 22 | $PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ; |
| 22 | $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ; | 23 | $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ; |
