1
0
mirror of https://github.com/cmur2/munin-postfix.git synced 2024-11-18 12:56:17 +01:00
munin-postfix/postfix_mailqueue
cn a3d1352877 Merged the syslog5mins script as a function into postfix_mailqueue
Removed standalone script, you may extract it at your wish.
2012-01-11 11:58:34 +01:00

153 lines
3.4 KiB
Bash
Executable File

#!/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
Inbound mail from the network.
=item outgoing
Mails that are sent to the network.
=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
=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
MAILLOG="/var/log/mail.log"
# 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
syslog5mins() {
#for (( i = 4; i >= 0; i-- )) ; do
for i in 4 3 2 1 0; do
# 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
case $1 in
autoconf|detect)
if [ -d $SPOOLDIR ] ; then
echo yes
exit 0
else
echo "no (spooldir not found)"
exit 0
fi;;
config)
cat <<'EOF'
graph_title Postfix Mailqueue
graph_vlabel Mails in queue
graph_category postfix
outgoing.label outgoing
outgoing.info Outbound mail to the network
deferred.label deferred
deferred.info Mail queued for later delivery
maildrop.label maildrop
maildrop.info Not yet picked up mail submitted via Postfix sendmail(1) command
incoming.label incoming
incoming.info Inbound mail from the network
corrupt.label corrupt
corrupt.info Unreadable or damaged queue files
hold.label held
hold.info Messages placed in the "hold" queue awaiting administrator intervention
EOF
for field in outgoing deferred maildrop incoming corrupt hold; do
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
outgoing.value `syslog5mins $MAILLOG | grep "postfix/smtp\[.*status=sent" | wc -l`
deferred.value `(test -d deferred && find deferred -type f ) | wc -l`
maildrop.value `(test -d maildrop && find maildrop -type f ) | wc -l`
incoming.value `syslog5mins $MAILLOG | grep "postfix/pipe\[.*status=sent" | wc -l`
corrupt.value `(test -d corrupt && find corrupt -type f ) | wc -l`
hold.value `( test -d hold && find hold -type f ) | wc -l`
EOF