2011-12-24 12:03:15 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
postfix_mailqueue - Plugin to monitor postfix mail spools
|
|
|
|
|
|
|
|
=head1 ABOUT
|
|
|
|
|
|
|
|
A guide to postfix mail queue manageent can be found at
|
|
|
|
L<http://www.postfix.org/QSHAPE_README.html#queues>
|
|
|
|
|
|
|
|
A summary:
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item maildrop
|
|
|
|
|
|
|
|
Messages that have been submitted via the Postfix sendmail(1) command,
|
|
|
|
but not yet brought into the main Postfix queue by the pickup(8)
|
|
|
|
service.
|
|
|
|
|
|
|
|
=item hold
|
|
|
|
|
|
|
|
Messages placed in the "hold" queue stay there until the administrator
|
|
|
|
intervenes
|
|
|
|
|
|
|
|
=item incoming
|
|
|
|
|
2011-12-24 12:16:55 +01:00
|
|
|
Inbound mail from the network.
|
2011-12-24 12:03:15 +01:00
|
|
|
|
2011-12-24 12:16:55 +01:00
|
|
|
=item outgoing
|
2011-12-24 12:03:15 +01:00
|
|
|
|
2011-12-24 12:16:55 +01:00
|
|
|
Mails that are sent to the network.
|
2011-12-24 12:03:15 +01:00
|
|
|
|
|
|
|
=item deferred
|
|
|
|
|
|
|
|
Mail that could not be delivered upon the first attempt. The queue manager
|
|
|
|
implements exponential backoff by doubling the time between delivery attempts.
|
|
|
|
|
|
|
|
=item corrupt
|
|
|
|
|
|
|
|
Unreadable or damaged queue files are moved here for inspection.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
By default "postconf -h queue_directory" is used to determine the
|
|
|
|
spool directory. Is postconf is not available in the $PATH then
|
|
|
|
/var/spool/postfix is assumed. This can be overridden by the
|
|
|
|
"spooldir" environment variable like so:
|
|
|
|
|
|
|
|
[postfix_mailqueue]
|
|
|
|
env.spooldir /var/spool/postfix
|
2012-01-13 21:38:13 +01:00
|
|
|
env.maillog /var/log/mail.log
|
2011-12-24 12:03:15 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Unknown.
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
Unknown.
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
=begin comment
|
|
|
|
|
|
|
|
These magic markers are used by munin-node-configure when installing
|
|
|
|
munin-node.
|
|
|
|
|
|
|
|
=end comment
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2012-01-13 21:38:13 +01:00
|
|
|
MAILLOG=${maillog:-/var/log/mail.log}
|
2013-09-10 20:48:28 +02:00
|
|
|
MINUTES=${minutes:-5}
|
|
|
|
OUTGOING_REGEX=${outgoing_regex:-postfix/smtp\[.*status=sent}
|
|
|
|
INCOMING_REGEX=${incoming_regex:-postfix/pipe\[.*status=sent}
|
2012-01-09 21:07:28 +01:00
|
|
|
|
2011-12-24 12:03:15 +01:00
|
|
|
# atempt to get spooldir via postconf, but environment overrides.
|
|
|
|
|
|
|
|
# Remember that postconf is not available unless postfix is.
|
|
|
|
POSTCONFSPOOL="$(postconf -h queue_directory 2>/dev/null || echo /var/spool/postfix)"
|
|
|
|
SPOOLDIR=${spooldir:-$POSTCONFSPOOL}
|
|
|
|
|
|
|
|
. $MUNIN_LIBDIR/plugins/plugin.sh
|
|
|
|
|
2013-09-10 20:48:28 +02:00
|
|
|
syslogXmins() {
|
2013-09-10 21:28:40 +02:00
|
|
|
MINUTES_MINUS_ONE=`expr $MINUTES - 1`
|
|
|
|
#for (( i = $MINUTES; i > 0; i-- )) ; do
|
2013-09-10 21:40:40 +02:00
|
|
|
for i in $(seq 0 $MINUTES_MINUS_ONE) ; do
|
2012-01-11 11:50:53 +01:00
|
|
|
# In %_d the underscore is important since it demands `date`
|
|
|
|
# to pad with spaces (like syslog for e.g. "Jan 1" to "Jan 9")
|
|
|
|
# instead of zeros.
|
|
|
|
dstring=`LANG=C date -d "-$i min" +"%b %_d %R"`
|
|
|
|
#echo "Entries for '$dstring':"
|
|
|
|
grep "^$dstring:.. " $1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# main logic
|
|
|
|
|
2011-12-24 12:03:15 +01:00
|
|
|
case $1 in
|
|
|
|
autoconf|detect)
|
|
|
|
if [ -d $SPOOLDIR ] ; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "no (spooldir not found)"
|
|
|
|
exit 0
|
2012-01-11 11:50:53 +01:00
|
|
|
fi;;
|
|
|
|
|
2011-12-24 12:03:15 +01:00
|
|
|
config)
|
|
|
|
cat <<'EOF'
|
|
|
|
graph_title Postfix Mailqueue
|
|
|
|
graph_vlabel Mails in queue
|
|
|
|
graph_category postfix
|
2011-12-24 12:16:55 +01:00
|
|
|
outgoing.label outgoing
|
|
|
|
outgoing.info Outbound mail to the network
|
2011-12-24 12:03:15 +01:00
|
|
|
deferred.label deferred
|
2011-12-24 12:16:55 +01:00
|
|
|
deferred.info Mail queued for later delivery
|
2011-12-24 12:03:15 +01:00
|
|
|
maildrop.label maildrop
|
2011-12-24 12:16:55 +01:00
|
|
|
maildrop.info Not yet picked up mail submitted via Postfix sendmail(1) command
|
2011-12-24 12:03:15 +01:00
|
|
|
incoming.label incoming
|
2011-12-24 12:16:55 +01:00
|
|
|
incoming.info Inbound mail from the network
|
2011-12-24 12:03:15 +01:00
|
|
|
corrupt.label corrupt
|
2011-12-24 12:16:55 +01:00
|
|
|
corrupt.info Unreadable or damaged queue files
|
2011-12-24 12:03:15 +01:00
|
|
|
hold.label held
|
2011-12-24 12:16:55 +01:00
|
|
|
hold.info Messages placed in the "hold" queue awaiting administrator intervention
|
2011-12-24 12:03:15 +01:00
|
|
|
EOF
|
2011-12-24 12:16:55 +01:00
|
|
|
for field in outgoing deferred maildrop incoming corrupt hold; do
|
2011-12-24 12:03:15 +01:00
|
|
|
print_warning $field
|
|
|
|
print_critical $field
|
|
|
|
done
|
|
|
|
exit 0;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
cd $SPOOLDIR >/dev/null 2>/dev/null || {
|
|
|
|
echo "# Cannot cd to $SPOOLDIR"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
cat <<EOF
|
2013-09-10 20:48:28 +02:00
|
|
|
outgoing.value `syslogXmins $MAILLOG | grep "$OUTGOING_REGEX" | wc -l`
|
2011-12-24 12:03:15 +01:00
|
|
|
deferred.value `(test -d deferred && find deferred -type f ) | wc -l`
|
|
|
|
maildrop.value `(test -d maildrop && find maildrop -type f ) | wc -l`
|
2013-09-10 20:48:28 +02:00
|
|
|
incoming.value `syslogXmins $MAILLOG | grep "$INCOMING_REGEX" | wc -l`
|
2011-12-24 12:03:15 +01:00
|
|
|
corrupt.value `(test -d corrupt && find corrupt -type f ) | wc -l`
|
|
|
|
hold.value `( test -d hold && find hold -type f ) | wc -l`
|
|
|
|
EOF
|