index 23bc521fa31732536e4f382681fc0b7aac434c0e..31eb46a4d5aa93da85f39e07e25b93f8930e6c39 100755 (executable)
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
+#
############################################################################
use POSIX;
# multi queue: one for each queue. overwrite on multi queue below
$msg_q = $1 ;
}
- } elsif (/^\s+Total\sRequests:\s(\d+)$/) {
+ } elsif (/^\s+Total\sRequests:\s(\d+)$/i) {
print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
#
# multi queue: last line
## close mailq
close (MAILQ);
- # declare an error if we also get a non-zero return code from mailq
- # unless already set to critical
+
if ( $? ) {
- $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
- print "STDERR $?: $!\n" if $verbose;
- $msg = "$state: (stderr)\n";
+ print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+ exit $ERRORS{CRITICAL};
}
## shut off the alarm
}
} # end of ($mailq eq "sendmail")
+elsif ( $mailq eq "postfix" ) {
+
+ ## 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'};
+ }
+ }elsif( defined $utils::PATH_TO_MAILQ){
+ unless (-x $utils::PATH_TO_MAILQ) {
+ print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+ } else {
+ print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+
+
+ @lines = reverse <MAILQ>;
+
+ # close qmail-qstat
+ close MAILQ;
+
+ if ( $? ) {
+ print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+ exit $ERRORS{CRITICAL};
+ }
+
+ ## shut off the alarm
+ alarm(0);
+
+ # check queue length
+ if ($lines[0]=~/Kbytes in (\d+)/) {
+ $msg_q = $1 ;
+ }elsif ($lines[0]=~/Mail queue is empty/) {
+ $msg_q = 0;
+ }else{
+ print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+
+ # check messages not processed
+ #if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
+ # my $msg_p = $1;
+ #}else{
+ # print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
+ # exit $ERRORS{'UNKNOWN'};
+ #}
+
+ # check queue length(s)
+ if ($msg_q == 0){
+ $msg = "OK: mailq reports queue is empty";
+ $state = $ERRORS{'OK'};
+ } else {
+ print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
+
+ # overall queue length
+ 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'};
+ }
+
+ # check messages not yet preprocessed (only compare is $opt_W and $opt_C
+ # are defined)
+
+ #if (defined $opt_W) {
+ # $msg .= "[Preprocessed = $msg_p]";
+ # if ($msg_p >= $opt_W && $msg_p < $opt_C ) {
+ # $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
+ # }elsif ($msg_p >= $opt_C ) {
+ # $state = $ERRORS{"CRITICAL"} ;
+ # }
+ #}
+ }
+} # end of ($mailq eq "postfixl")
elsif ( $mailq eq "qmail" ) {
# open qmail-qstat
# close qmail-qstat
close MAILQ;
- # declare an error if we also get a non-zero return code from mailq
- # unless already set to critical
+
if ( $? ) {
- $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
- print "STDERR $?: $!\n" if $verbose;
- $msg = "$state: (stderr)\n";
+ print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+ exit $ERRORS{CRITICAL};
}
## shut off the alarm
} # end of ($mailq eq "qmail")
+elsif ( $mailq eq "exim" ) {
+ ## 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'};
+ }
+ }elsif( defined $utils::PATH_TO_MAILQ){
+ unless (-x $utils::PATH_TO_MAILQ) {
+ print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+ } else {
+ print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
+ exit $ERRORS{'UNKNOWN'};
+ }
+
+ while (<MAILQ>) {
+ #22m 1.7K 19aEEr-0007hx-Dy <> *** frozen ***
+ #root@exlixams.glups.fr
+ if (/\s[\w\d]{6}-[\w\d]{6}-[\w\d]{2}\s/) { # message id 19aEEr-0007hx-Dy
+ $msg_q++ ;
+ }
+ }
+ close(MAILQ) ;
+ if ( $? ) {
+ print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
+ exit $ERRORS{CRITICAL};
+ }
+ 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'};
+ }
+} # end of ($mailq eq "exim")
# Perfdata support
-print "$msg |mailq=$msg_q\n";
+print "$msg|unsent=$msg_q;$opt_w;$opt_c;0\n";
exit $state;
"M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail)
"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
- "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$ ');
+ print_revision($PROGNAME,'@NP_VERSION@');
exit $ERRORS{'OK'};
}
}
if (defined $opt_M) {
- if ($opt_M =~ /sendmail/ || $opt_M =~ /qmail/ ) {
+ if ($opt_M =~ /^(sendmail|qmail|postfix|exim)$/) {
$mailq = $opt_M ;
}elsif( $opt_M eq ''){
$mailq = 'sendmail';
}
sub print_usage () {
- print "Usage: $PROGNAME [-w <warn>] [-c <crit>] [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n";
+ print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n";
}
sub print_help () {
- print_revision($PROGNAME,'$Revision$');
+ print_revision($PROGNAME,'@NP_VERSION@');
print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n";
print "\n";
print_usage();
print " Checks the number of messages in the mail queue (supports multiple sendmail queues, qmail)\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 "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n";
print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n";
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 ] (default = sendmail)\n";
+ print "-M (--mailserver) = [ sendmail | qmail | postfix | exim ] (default = sendmail)\n";
print "-h (--help)\n";
print "-V (--version)\n";
print "-v (--verbose) = debugging output\n";