summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a7fed94)
raw | patch | inline | side by side (parent: a7fed94)
author | Subhendu Ghosh <sghosh@users.sourceforge.net> | |
Wed, 30 Oct 2002 05:07:29 +0000 (05:07 +0000) | ||
committer | Subhendu Ghosh <sghosh@users.sourceforge.net> | |
Wed, 30 Oct 2002 05:07:29 +0000 (05:07 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@163 f882894a-f735-0410-b71e-b25c423dba1c
acconfig.h | patch | blob | history | |
configure.in | patch | blob | history | |
plugins-scripts/Makefile.am | patch | blob | history | |
plugins-scripts/check_mailq.pl | [new file with mode: 0755] | patch | blob |
plugins-scripts/utils.pm.in | patch | blob | history |
diff --git a/acconfig.h b/acconfig.h
index 84b2e9c57af2aa3ca24110a1ef98725be1ed5f91..55fb9a2ca9eb982ec70c5324843fc849581dd4bb 100644 (file)
--- a/acconfig.h
+++ b/acconfig.h
#undef PATH_TO_NTPDC
#undef PATH_TO_LMSTAT
#undef PATH_TO_SMBCLIENT
+#undef PATH_TO_MAILQ
#undef PING_COMMAND
#undef PING_PACKETS_FIRST
#undef POSIX_STATE_DEFS
diff --git a/configure.in b/configure.in
index ea5c12536ab922180bce1d21a69e9405b5b9f216..aa68894d21336efa8dd4cc5908bd757a6e161d25 100644 (file)
--- a/configure.in
+++ b/configure.in
echo "** Get ssh in order to make check_by_ssh plugin"
fi
+
+AC_PATH_PROG(PATH_TO_MAILQ,mailq)
+if test -x "$PATH_TO_MAILQ"
+then
+ AC_DEFINE_UNQUOTED(PATH_TO_MAILQ,"$PATH_TO_MAILQ",[path to mailq])
+else
+ echo "** Could not find mailq or eqivalent"
+fi
+
dnl dunno why this does not work below - use hack (kbd)
dnl fine on linux, broken on solaris
dnl if /bin/test -e "/proc/meminfo"
index 1ca1549e9729289a098e0cd9c603328b39c51db5..5377bf44a9101178f81dc8f3e620a96b57f245a2 100644 (file)
libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \
check_log check_ntp check_oracle check_rpc check_sensors check_wave \
- check_ifstatus check_ifoperstatus utils.sh utils.pm
+ check_ifstatus check_ifoperstatus check_mailq utils.sh utils.pm
EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \
check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \
- check_ifstatus.pl check_ifoperstatus.pl check_wave.pl utils.sh.in utils.pm.in t
+ check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl utils.sh.in utils.pm.in t
TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir)
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
--- /dev/null
@@ -0,0 +1,179 @@
+#!/usr/local/bin/perl -w
+
+# check_mailq - check to see how many messages are in the smtp queue awating
+# transmittal.
+#
+# Initial version support sendmail's mailq command
+
+# License Information:
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+############################################################################
+
+use POSIX;
+use strict;
+use Getopt::Long;
+use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $status $state $msg $msg_q );
+use lib utils.pm;
+use utils qw(%ERRORS &print_revision &support &usage );
+
+#my $MAILQ = "/usr/bin/mailq"; # need to migrate support to utils.pm and autoconf
+
+
+sub print_help ();
+sub print_usage ();
+sub process_arguments ();
+
+$ENV{'PATH'}='';
+$ENV{'BASH_ENV'}='';
+$ENV{'ENV'}='';
+$PROGNAME = "check_mailq";
+
+Getopt::Long::Configure('bundling');
+$status = process_arguments();
+if ($status){
+ print "ERROR: processing arguments\n";
+ exit $ERRORS{"UNKNOWN"};
+}
+
+$SIG{'ALRM'} = sub {
+ print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
+ exit $ERRORS{"WARNING"};
+};
+alarm($opt_t);
+
+## open mailq
+if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
+ if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
+ print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+}else{
+ print "ERROR: Could not find mailq executable!\n";
+ exit $ERRORS{'UNKNOWN'};
+}
+
+# only first line is relevant in this iteration.
+while (<MAILQ>) {
+ if (/mqueue/) {
+ print "$utils::PATH_TO_MAILQ = $_ "if $verbose ;
+ if (/empty/ ) {
+ $msg = "OK: mailq is empty";
+ $msg_q = 0;
+ $state = $ERRORS{'OK'};
+ }elsif ( /(\d+)/ ) {
+ $msg_q = $1 ;
+
+ print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
+
+ if ($msg_q < $opt_w) {
+ $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
+ $state = $ERRORS{'OK'};
+ }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
+ $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)";
+ $state = $ERRORS{'WARNING'};
+ }else {
+ $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)";
+ $state = $ERRORS{'CRITICAL'};
+ }
+
+ }
+
+ last;
+ }
+
+}
+
+close (MAILQ);
+# declare an error if we also get a non-zero return code from mailq
+# unless already set to critical
+if ( $? ) {
+ print "stderr = $? : $! \n" if $verbose;
+ $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"UNKNOWN"} ;
+ print "MAILQ error: $!\n" if $verbose;
+}
+## close mailq
+
+# Perfdata support
+print "$msg | mailq = $msg_q\n";
+exit $state;
+
+
+#####################################
+#### subs
+
+
+sub process_arguments(){
+ GetOptions
+ ("V" => \$opt_V, "version" => \$opt_V,
+ "v" => \$opt_v, "verbose" => \$opt_v,
+ "h" => \$opt_h, "help" => \$opt_h,
+ "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
+ );
+
+ if ($opt_V) {
+ print_revision($PROGNAME,'$Revision$ ');
+ exit $ERRORS{'OK'};
+ }
+
+ if ($opt_h) {
+ print_help();
+ exit $ERRORS{'OK'};
+ }
+
+ if (defined $opt_v ){
+ $verbose = $opt_v;
+ }
+
+ unless (defined $opt_t) {
+ $opt_t = $utils::TIMEOUT ; # default timeout
+ }
+
+ unless ( defined $opt_w && defined $opt_c ) {
+ print_usage();
+ exit $ERRORS{'UNKNOWN'};
+ }
+
+ if ( $opt_w >= $opt_c) {
+ print "Warning cannot be greater than Critical!\n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+
+ return $ERRORS{'OK'};
+}
+
+sub print_usage () {
+ print "Usage: $PROGNAME [-w <warn>] [-c <crit>] [-t <timeout>] [-v verbose]\n";
+}
+
+sub print_help () {
+ print_revision($PROGNAME,'$Revision$');
+ print "Copyright (c) 2002 Subhendu Ghosh\n";
+ print "\n";
+ print_usage();
+ print "\n";
+ print " Checks the number of messages in the mail queue\n";
+ 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 queu to generate critical alert ( w < c )\n";
+ print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
+ print "-h (--help)\n";
+ print "-V (--version)\n";
+ print "-v (--verbose) = deebugging output\n";
+ print "\n\n";
+ support();
+}
index fe9bc24a1a10910fdf5293acd4cd2a22cd9c77e8..05735eb4f7056343f0597b44bf4fd2868d8f3b3a 100644 (file)
# $Id$
#
# $Log$
+# Revision 1.5 2002/10/30 05:07:29 sghosh
+# monitor mailq
+#
# Revision 1.4 2002/05/27 02:01:09 sghosh
# new var - smbclient
#
$PATH_TO_NTPDC = "@PATH_TO_NTPDC@" ;
$PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
+$PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
## common variables
$TIMEOUT = 15;