#!/bin/sh
# 
# Plugin to monitor postfix mail spools
# 
# Contributed by Nicolai Langfeldt
# 
# $Log$
# Revision 1.4  2004/05/20 19:02:36  jimmyo
# Set categories on a bunch of plugins
#
# Revision 1.3  2004/05/14 21:16:46  jimmyo
# "Upped" som plugins from contrib/manual to auto.
#
# Revision 1.2  2004/05/09 21:11:15  jimmyo
# New plugin (pm3users) and a bunch of patches from Jacques Caruso.
#
# Revision 1.1  2004/01/02 18:50:00  jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.2  2003/11/26 14:55:52  jimmyo
# Added total summaries
#
# Revision 1.1  2003/11/26 09:10:28  jimmyo
# Plugin contribution by Nicolai Langfeldt
#
# 
#%# family=auto
#%# capabilities=autoconf

# Can be set via environment, but default is /var/spool/postfix
SPOOLDIR=${spooldir:-/var/spool/postfix}

# Postfix mqueue management: http://www.postfix.cs.uu.nl/queuing.html
# maildrop: Localy posted mail
# incoming: Processed local mail and received from network
# active: Mails being delivered (should be small)
# deferred: Stuck mails (that will be retried later)
# corrupt: Messages found to not be in correct format (shold be 0)
# hold: Recent addition, messages put on hold indefinitly - delete of free

case $1 in
    autoconf|detect)
	if [ -d $SPOOLDIR/ ] ; then
	    echo yes
	    exit 0
        else
	    echo "no (spooldir not found)"
	    exit 1
        fi;;
    config)
	cat <<'EOF'
graph_title Postfix Mailqueue
graph_vlabel Mails in queue
graph_category postfix
graph_total Total
active.label active
deferred.label deferred
maildrop.label maildrop
incoming.label incoming
corrupt.label corrupt
hold.label held
EOF
	exit 0;;
esac

cd $SPOOLDIR >/dev/null 2>/dev/null || {
     echo "# Cannot cd to $SPOOLDIR"
     exit 1
}

cat <<EOF
deferred.value `(test -d deferred && find deferred -type f ) | wc -l`
active.value `(test -d active && find active -type f ) | wc -l`
maildrop.value `(test -d maildrop && find maildrop -type f ) | wc -l`
incoming.value `(test -d incoming && find incoming -type f ) | 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
