In case anyone is interested, I've attached a working Postfix Mail Queue
Monitor for nagios - It's working for me as is, but if anyone has any
suggested modifications I'd be glad to look at them.
Thanks,
Scott Miller
#! /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/nagios/libexec" ;
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/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'};
}
#
############################################################
################################################################################
#
# SAMPLE SERVICE CHECK COMMANDS
#
# These are some example service check commands. They may or may not work on
# your system, as they must be modified for your plugins. See the HTML
# documentation on the plugins for examples of how to configure command
definitions.
#
# NOTE: The following 'check_local_...' functions are designed to monitor
# various metrics on the host that Nagios is running on (i.e. this one).
################################################################################
# 'check_postfix_mailq' command definition
define command{
command_name check_postfix_mailq
command_line $USER1$/check_postfix_mailq -w $ARG1$ -c $ARG2$ -p
$ARG3$
}
# 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_postfix_mailq!50!100
}
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Nagios-users mailing list
Nagios-users@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