#!/bin/sh
#
# Plugin to monitor sendmail queue size.
#
# Usage: Place in /etc/lrrd/client.d/ (or link it there  using ln -s)
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional)
#
# Config variables:
#
#       mspqueue     - MSQ queue directory
#       mtaqueue     - MTA queue directory
#
# $Log$
# Revision 1.5.2.1  2005/02/16 19:05:40  jimmyo
# generic/sendmail_mailqueue handles bigger queues (fix by Mickey Everts).
#
# Revision 1.5  2004/11/20 19:31:59  jimmyo
# Fixed bug in generic/sendmail_mailqueue, when queue is empty.
#
# 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/02/18 18:40:02  jimmyo
# Added Log:
#
#%# family=auto
#%# capabilities=autoconf

MSP_QUEUE=/var/spool/mqueue-client
MTA_QUEUE=/var/spool/mqueue
if [ "$mspqueue"  ]; then MSP_QUEUE=$mspqueue ; fi
if [ "$mtaqueue"  ]; then MTA_QUEUE=$mspqueue ; fi

if [ "$1" = "autoconf" ]; then
	if [ -d ${MSP_QUEUE} -a -d ${MTA_QUEUE} ] ; then
		echo yes
		exit 0
	else
		echo no
		exit 1
	fi
fi

if [ "$1" = "config" ]; then

	echo 'graph_title Sendmail queued mails'
	echo 'graph_order mails'
	echo 'graph_vlabel mails in queue'
	echo 'graph_category sendmail'
	echo 'mails.label mails'
	exit 0
fi

mspmails=`find ${MSP_QUEUE} -type f -name '[qQ]*' 2>/dev/null | wc -l`
mtamails=`find ${MTA_QUEUE} -type f -name '[qQ]*' 2>/dev/null | wc -l`
echo "mails.value `expr ${mspmails} + ${mtamails}`"
