Postfix Mail Queue Plugin

Scott Miller srmiller at interbel.com
Thu Jul 1 22:50:20 CEST 2010


Hello all,

   I'm wanting to monitor a Postifx Mail Queue on a local machine, and found the below plugin (some years ago).  The machine is a FreeBSD 8 with Nagios 3.2.1 and Postfix 2.7.0.  I’ve used the below plugin on a Fedora 8 machine, with no problems, but FreeBSD seems to have problems with it.  The error reads: (Service check did not exit properly) and the logs show: Warning: Check of service 'Postfix Mail Queue' on host 'localhost' did not exit properly!

   I did modify just one line:

use lib "/usr/local/nagios/libexec" ;
to
use lib "/usr/local/libexec/nagios" ;

Anyone see what I’m doing wrong?  I've googled and googled, but to no avail.

Thanks!
Scott Miller

--------------------------------
--------------------------------
#check_mailq


#! /usr/bin/perl -w

# Copyright (c) 2002 Oregon State University - Network Engineering
# All rights reserved.
#
# $Id: check_postfix_mailq,v 1.2 2004/11/18 21:01:58 kveton Exp $
# $Source: /data/cvsroot/eng/nagios/check_postfix_mailq,v $

# This is a Nagios monitoring plugin that will check the status of 
#   the Postfix mailq on the local machine.  It is best used with
#   something like NRPE for remote access.

BEGIN {
	if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
		$PROGNAME = $2;
	}
}

require 5.004;
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 "/usr/local/libexec/nagios" ;
use utils qw(%ERRORS &print_revision &usage &support);

use Data::Dumper;

# function prototypes
sub print_help ();
sub print_usage ($);
sub help ();
sub version ();
sub get_version ();

# paranoia central
delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
$PROGNAME = "check_mailq";

Getopt::Long::Configure('bundling', 'no_ignore_case');
GetOptions
	("V|version"    => \&version,
	 "h|help"       => \&help,
	 "w|warning=s"  => \$opt_w,
	 "c|critical=s" => \$opt_c);

# set the defaults for warn
($opt_w) || ($opt_w = shift) || ($opt_w = 2000);
my $warning = $1 if ($opt_w =~ /([0-9]+)/);

# set the defaults for critical
($opt_c) || ($opt_c = shift) || ($opt_c = 5000);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);

# for the final processing of the output
my $state  = 'UNKNOWN';
my $answer = 'Could not initialize tests.';

# Just in case of problems, let's not hang NetSaint
$SIG{'ALRM'} = sub {
	print ("ERROR: No response from postfix mailq (alarm)\n");
	exit $ERRORS{"UNKNOWN"};
};
alarm(30);

# let's get to it
my $result = `/usr/local/sbin/postqueue -p`;

if ( $result =~ /-- (\d+) Kbytes in (\d+) Request[s]*\./ ) {
        if ( $2 > $critical ) {
                $state = 'CRITICAL';
        }
	elsif ( $2 > $warning ) {
		$state = 'WARNING';
	}
	else {
		$state = 'OK';
	}

	$answer = "Postfix mailq has $2 messages queued for a total of $1 Kbytes.";
}
elsif ( $result =~ /Mail queue is empty/ ) {
	$state = 'OK';
	$answer = 'Mail queue is empty';
}
else {
	$state = 'CRITICAL';
	$answer = "Could not connect to local mailq.  Postfix may be down.";
}

if ( $state eq 'CRITICAL' or $state eq 'WARNING' or $state eq 'UNKNOWN' ) {
        print "$state: $answer\n";
}
else {
        print "OK: $answer\n";
}

exit $ERRORS{$state};

#
############################################################3

############################################################3
# Standard Netsaint Support Functions
sub print_usage ($) {
	my ($error) = @_;

	print "Usage: $PROGNAME [--help|h] [-w <warn>] [-c <crit>]\n";

	if ( $error ) {
		print "$error\n";
		exit $ERRORS{'UNKNOWN'};
        }
}

sub get_version () {
	return '$ Revision: 1.0.0 $';
}

sub print_help () {
	my $version = get_version();
	print "\nCopyright (c) 2002 Oregon State University -- $PROGNAME, $version\n";
	print_usage('');
	my $usage = qq{
		-w	Warning service page threshold.
		-c	Critical service page threshold.
		-h	This message.

};
	print $usage;
}

sub version () {
	print_revision($PROGNAME, get_version() );
	exit $ERRORS{'OK'};
}

sub help () {
	print_help();
	exit $ERRORS{'OK'};
}
#
############################################################

--------------------------------
--------------------------------
#commands.cfg

# 'check_mailq' command definition
define command{
        command_name    check_mailq
        command_line    $USER1$/check_mailq -w $ARG1$ -c $ARG2$
        }
--------------------------------
--------------------------------
#localhost.cfg

# Define a service to check mailq on postfix mail server
# warning of > 50
# critical if > 100

define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Postfix Mail Queue
	check_command			check_mailq!50!100
        }


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list