From: "Scott Miller" on
This is a multipart message in MIME format.

------=_NextPart_000_0343_01CA40E5.AD24D0C0
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: 7bit

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

------=_NextPart_000_0343_01CA40E5.AD24D0C0
Content-Type: text/plain;
name="check_postfix_mailq.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="check_postfix_mailq.txt"

#! /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=20
# the Postfix mailq on the local machine. It is best used with
# something like NRPE for remote access.

BEGIN {
if ($0 =3D~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
$PROGNAME =3D $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 =3D "check_mailq";

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

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

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

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

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

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

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

$answer =3D "Postfix mailq has $2 messages queued for a total of $1 =
Kbytes.";
}
elsif ( $result =3D~ /Mail queue is empty/ ) {
$state =3D 'OK';
$answer =3D 'Mail queue is empty';
}
else {
$state =3D 'CRITICAL';
$answer =3D "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) =3D @_;

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 =3D get_version();
print "\nCopyright (c) 2002 Oregon State University -- $PROGNAME, =
$version\n";
print_usage('');
my $usage =3D 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'};
}
#
############################################################


------=_NextPart_000_0343_01CA40E5.AD24D0C0
Content-Type: text/plain;
name="commands.cfg.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="commands.cfg.txt"

#########################################################################=
#######
#
# 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=20
# 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$
}
------=_NextPart_000_0343_01CA40E5.AD24D0C0
Content-Type: text/plain;
name="localhost.cfg.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="localhost.cfg.txt"

# 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
}
------=_NextPart_000_0343_01CA40E5.AD24D0C0--

From: Barney Desmond on
2009/9/30 Scott Miller <srmiller(a)interbel.net>:
> 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.

We do something like this where I work, a mailqueue-size check for
nagios via NRPE. There was some discussion a little while ago finding
the queue size; the long and the short is that invoking postqueue is
bad (it's painfully slow).

If you're interested, dig up the thread in your favourite archives and
have a read, the subject is/was "Recommended way to (quickly) get
total mail queue size?", around 2009-07-08.

I'm in the process of improving our own systems, which will move to
using Victor's suggested perl script. In some ad-hoc testing, I reckon
it's easily 1-2 orders of magnitude faster than postqueue when there's
a fair amount of mail queued up.

P.S. Apologies if I'm wrong about the script using postqueue, but I
didn't read every single line, just had a skim to appease my
suspicions.
From: "Len Conrad" on
>2009/9/30 Scott Miller <srmiller(a)interbel.net>:
>> 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.
>
>We do something like this where I work, a mailqueue-size check for
>nagios via NRPE. There was some discussion a little while ago finding
>the queue size; the long and the short is that invoking postqueue is
>bad (it's painfully slow).
>
>If you're interested, dig up the thread in your favourite archives and
>have a read, the subject is/was "Recommended way to (quickly) get
>total mail queue size?", around 2009-07-08.
>
>I'm in the process of improving our own systems, which will move to
>using Victor's suggested perl script. In some ad-hoc testing, I reckon
>it's easily 1-2 orders of magnitude faster than postqueue when there's
>a fair amount of mail queued up.
>
>P.S. Apologies if I'm wrong about the script using postqueue, but I
>didn't read every single line, just had a skim to appease my
>suspicions.

here's mine, very fast with "find":

#!/bin/sh

for Q in incoming active deferred hold ; do

SIZE="`find /mail/spool/postfix/$Q -maxdepth 5 -type f | wc -l | tr -d ' ' `"

dd if=/dev/zero bs=1 count=$SIZE of=/var/db/postfix/q_size_$Q

done

exit 0


then I have monit monitor the filesizes of those 4 files.

Len

From: Victor Duchovni on
On Tue, Sep 29, 2009 at 10:55:32PM +0200, Len Conrad wrote:

> here's mine, very fast with "find":
>
> #!/bin/sh
>
> for Q in incoming active deferred hold
> do
> SIZE=`find /mail/spool/postfix/$Q -maxdepth 5 -type f | wc -l | tr -d ' '`
> dd if=/dev/zero bs=1 count=$SIZE of=/var/db/postfix/q_size_$Q
> done
> exit 0

The find(1) is less efficient than it should be, because you don't need
to lstat(2) the files as with "-type f". All the sub-directories of
the queues have single-letter names, and all the queue-files have
multi-letter names. With a POSIX shell, avoid the `cmd` construct.

n=$$( $(find /var/spool/postfix/$Q ! -name "?" ! | wc -l) - 1 )

--
Viktor.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:majordomo(a)postfix.org?body=unsubscribe%20postfix-users>

If my response solves your problem, the best way to thank me is to not
send an "it worked, thanks" follow-up. If you must respond, please put
"It worked, thanks" in the "Subject" so I can delete these quickly.