#!/bin/sh 
# 
# agent to monitor the mail queue size (number of queued files in the mail 
# queue) 
# 
# contributed by Wulf Dietrich, w_dietrich@hotmail.com, 03/23/2000 
# 
# 
# Usage: 
# contrib:mqsz:0-24:15:8:enabled:/var/spool/mqueue=5=50: 
# 
# needs to run: chmod o+rx /var/spool/mqueue 
# this is not a lack on privacy, because mail messages still readable from 
# root only (on AIXi and SuSE-Linux at least) 
# 
# developed on AIX 

#. /usr/local/bcnu/etc/bcnuenv 
. $BCNUHOME/agent/agent_head 

OK=1 
ERR="" 
WARN="" 

for param in $BCNUPARAM ; do 

bcnu_param 
QDIR=$p1 
NU_WARN=${p2:=5} 
NU_ERR=${p3:=50} 

if [ -d $QDIR -a -r $QDIR -a -x $QDIR ] ; then 
NU_ACT=`ls $QDIR/qf* 2>/dev/null | wc -l` 
else 
BCNUMSG="$BCNU -m 'error - unexpected queue dir permissions' -e $BCNU_ERR -t $BCNUHOSTTYPE $BCNUHOST" 
bcnu_err_send 
exit 
fi 

if [ $NU_ACT -ge $NU_ERR ] ; then 
OK="" 
ERR=1 
elif [ $NU_ACT -ge $NU_WARN ] ; then 
OK="" 
WARN=1 
fi 
done 


if [ $OK ] ; then 
BCNUMSG="$BCNU -m 'ok - $NU_ACT mails queued (<$NU_WARN)' -e $BCNU_OK -t $BCNUHOSTTYPE $BCNUHOST" 
bcnu_send 
else 
if ! [ $ERR ] ; then 
if [ $WARN ] ; then 
BCNUMSG="$BCNU -m 'warning - $NU_ACT mails queued (>=$NU_WARN)' -e $BCNU_WARN -t $BCNUHOSTTYPE $BCNUHOST" 
bcnu_warn_send 
fi 
else 
BCNUMSG="$BCNU -m 'error - $NU_ACT mails queued (>=$NU_ERR)' -e $BCNU_ERR -t $BCNUHOSTTYPE $BCNUHOST" 
bcnu_err_send 
fi 
fi 

