#!/bin/sh --
#
# check a bunch of mail queues
# by Doke Scott, doke at udel dot edu, 14 Jan 2004
#
# $Header: /usr/local/home/doke/work/nagios/RCS/check_mqueues.sh,v 1.1 2005/05/07 00:08:18 doke Exp $

#set -x

PATH=/usr/local/nagios/libexec:/usr/bin:/usr/sbin
export PATH

tmp=/tmp/check_mqueues.$$.tmp 
/bin/rm -f $tmp
umask 077
touch $tmp

for d in /var/spool/mqueue/qd* /var/spool/mqueue/qd*/qf /var/spool/clientmqueue; do 
    if [ -d $d ]; then 
        check_dircount -w 1000 -c 2000 $d >> $tmp
    fi
done

if grep "CRITICAL" $tmp; then
    /bin/rm -f $tmp
    exit 2; 
elif grep "Warning" $tmp; then 
    /bin/rm -f $tmp
    exit 1;
else
    /bin/rm -f $tmp
    echo "OK"
    exit 0;
fi

