--- plugins-scripts/utils.pm.in.orig 2004-01-13 12:45:04.000000000 -0500 +++ plugins-scripts/utils.pm.in 2004-01-13 12:45:39.000000000 -0500 @@ -43,6 +43,7 @@ $PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ; $PATH_TO_MAILQ = "@PATH_TO_MAILQ@"; $PATH_TO_QMAIL_QSTAT = "@PATH_TO_QMAIL_QSTAT@"; +$PATH_TO_SENDMAIL_CF = "@PATH_TO_SENDMAIL_CF@"; ## common variables $TIMEOUT = 15; --- plugins-scripts/check_mailq.pl.orig 2004-01-13 12:45:47.000000000 -0500 +++ plugins-scripts/check_mailq.pl 2004-01-20 14:53:05.000000000 -0500 @@ -28,15 +28,16 @@ use strict; use Getopt::Long; use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t - $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines - %srcdomains %dstdomains); + $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $opt_f + $mailq @lines %srcdomains %dstdomains); use lib utils.pm; use utils qw(%ERRORS &print_revision &support &usage ); - +use File::Glob ':glob'; sub print_help (); sub print_usage (); sub process_arguments (); +sub get_queue_directories (;$); $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; @@ -47,7 +48,7 @@ $msg_p = 0 ; $state = $ERRORS{'UNKNOWN'}; -Getopt::Long::Configure('bundling'); +Getopt::Long::Configure('bundling','no_ignore_case'); $status = process_arguments(); if ($status){ print "ERROR: processing arguments\n"; @@ -64,6 +65,22 @@ if ($mailq eq "sendmail") { +## get configuration file, and from that, the queue directories + my @queuedirs=(); + my $configfile=""; + if ( defined($opt_f) && -r $opt_f ) { + $configfile="-C$opt_f"; + @queuedirs=get_queue_directories($opt_f); + }else { + @queuedirs=get_queue_directories(); + } + + if (!defined($queuedirs[0])) { + print "UNKNOWN: check_mailq: no queue directories | msq_q = 0\n"; + exit $ERRORS{"UNKNOWN"}; + } + my $qpattern=join("|",@queuedirs); + ## open mailq if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) { @@ -163,21 +180,16 @@ # Finally look at the overall queue length # - if (/mqueue/) { + # the pattern helps us get one or more queue directories, and adds up + # all the requests + if (/\b$qpattern\b/) { print "$utils::PATH_TO_MAILQ = $_ "if $verbose ; - if (/ \((\d+) request/) { - # - # single queue: first line - # multi queue: one for each queue. overwrite on multi queue below - $msg_q = $1 ; + if (/empty/) { + }elsif (/\((\d+)\s*requests\)/i) { + $msg_q+=$1; + print "size = $1, msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; } - } elsif (/^\s+Total\sRequests:\s(\d+)$/) { - print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ; - # - # multi queue: last line - $msg_q = $1 ; } - } @@ -519,7 +531,8 @@ "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number "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 + "t=i" => \$opt_t, "timeout=i" => \$opt_t, + "f=s" => \$opt_f, "configfile" => \$opt_f ); if ($opt_V) { @@ -572,12 +585,19 @@ }else{ $mailq = 'sendmail' ; } + + if (defined $opt_f) { + if (! -r $opt_f) { + print "Can't read config file (-f): $opt_f!W\n"; + exit $ERRORS{'UNKNOWN'}; + } + } return $ERRORS{'OK'}; } sub print_usage () { - print "Usage: $PROGNAME -w -c [-W ] [-C ] [-M ] [-t ] [-v verbose]\n"; + print "Usage: $PROGNAME -w -c [-W ] [-C ] [-M ] [-t ] [-v verbose] [-f configfile]\n"; } sub print_help () { @@ -594,6 +614,7 @@ print "-C (--Critical) = 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 ] (default = sendmail)\n"; + print "-f (--configfile) = configuration file for sendmail (default = $utils::PATH_TO_SENDMAIL_CF)\n"; print "-h (--help)\n"; print "-V (--version)\n"; print "-v (--verbose) = debugging output\n"; @@ -608,3 +629,45 @@ print "\n\n"; support(); } + +sub get_queue_directories (;$) +{ + my $cfin=shift; + my @cfs=(); + my @qdirs=(); + + if ($cfin) { + @cfs=($cfin); + }else { + if (-r $utils::PATH_TO_SENDMAIL_CF) { + @cfs=($utils::PATH_TO_SENDMAIL_CF); + }else { + @cfs=qw(/etc/mail/sendmail.cf); + } + } + + my @cffiles=grep { -r $_} @cfs; + if (scalar(@cffiles)==0) { + warn "unable to find a sendmail configuration file"; + return (undef); + } + + my $qdir; + foreach my $cf (@cffiles) { + if (open(CF,$cf)) { + while() { + chomp; + next unless (/^O\s*QueueDirectory=(.*)$/ && ($qdir=$1)); + push(@qdirs,bsd_glob($qdir)); + last; + } + } + close(CF); + } + + if (@qdirs==0) { + warn "no QueueDirectory variable found in sendmail configuration file"; + return (undef); + }; + return @qdirs; +}