#!/usr/bin/perl -w # check_exim_input - check to see how many "-H" files are in the Exim input # queue instead of running mailq to save on system resources. # # Based on: # check_eximq - check to see how many messages are in the smtp queue awating # transmittal. # # 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 $opt_q $status $state $msg $msg_q $input_dir $PATH_TO_FIND $FIND_ARGS); use lib "/valve/nagios/libexec" ; use utils qw(%ERRORS &print_revision &support &usage ); sub print_help (); sub print_usage (); sub process_arguments (); $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; $PROGNAME = "check_exim_input"; $input_dir = ''; $PATH_TO_FIND = '/usr/bin/find'; $FIND_ARGS = '-type f -name *-H'; $msg_q = 0 ; $state = $ERRORS{'UNKNOWN'}; 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 $PATH_TO_FIND $input_dir $FIND_ARGS\n"); exit $ERRORS{"WARNING"}; }; alarm($opt_t); ## open mailq if ( defined $PATH_TO_FIND && -x $PATH_TO_FIND ) { if ($verbose) { print "\n Calling input find as: $PATH_TO_FIND $input_dir $FIND_ARGS\n"; } if (! open (MAILQ, "$PATH_TO_FIND $input_dir $FIND_ARGS 2>&1 | " ) ) { print "ERROR: could not open $PATH_TO_FIND $input_dir $FIND_ARGS\n"; exit $ERRORS{'UNKNOWN'}; } } elsif ( defined $PATH_TO_FIND ) { unless (-x $PATH_TO_FIND) { print "ERROR: $PATH_TO_FIND is not executable by (uid $>:gid($)))\n"; exit $ERRORS{'UNKNOWN'}; } } else { print "ERROR: \$PATH_TO_FIND is not defined\n"; exit $ERRORS{'UNKNOWN'}; } while () { # /var/spool/exim/input/r/1DWq2r-0001iP-00-H if (/.*[\w\d]{6}-[\w\d]{6}-[\w\d]{2}-[\w\d]{1}\s/) { $msg_q++ ; } } close(MAILQ) ; if ( $? > 0 ) { print "ERROR: find exited with non-zero status (error $?).\n"; exit $ERRORS{'UNKNOWN'}; } 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'}; } # Perfdata support print "$msg|unsent=$msg_q;$opt_w;$opt_c;0\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, "q=s" => \$opt_q, "inputdir=s" => \$opt_q ); if ($opt_V) { print_revision($PROGNAME,'$Revision: 1.2 $ '); 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 (-w) cannot be greater than Critical (-c)!\n"; exit $ERRORS{'UNKNOWN'}; } if ( defined $opt_q ) { $input_dir = $opt_q; if ($verbose) { print "\n input dir argument = $input_dir\n"; } } return $ERRORS{'OK'}; } sub print_usage () { print "Usage: $PROGNAME -w -c [-t ] [-v verbose] [-q ]\n"; } sub print_help () { print_revision($PROGNAME,'$Revision: 1.2 $'); print "Copyright (c) 2005 Bryn Wm. Moslow\n"; print "Hacked to pieces and derived from check_mailq...\n"; print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n"; print "\n"; print_usage(); print "\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 "-q (--inputdir) = Path to Exim input directory\n"; print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; print "-h (--help)\n"; print "-V (--version)\n"; print "-v (--verbose) = debugging output\n"; print "\n\n"; print " Note: -w and -c are required arguments.\n"; print "\n"; print " This plugin uses the system find command to look\n"; print " at the Exim input directory. May only be accessed by root \n"; print " or a TrustedUser. You will have to set appropriate \n"; print " permissions for the plugin to work.\n"; print ""; print "\n\n"; support(); }