1
0
Fork 0
scripts-admin-quickndirty-p.../nagios/check_sendmail_queue.sh

96 lines
1.7 KiB
Bash
Executable file

#!/bin/sh
# Replace COMMANDE by mailq if you want both new and old messages listed
COMMANDE="/usr/sbin/sendmail -bp"
WARNING_REQ=10
CRITICAL_REQ=15
WARNING_SIZE=20000000
CRITICAL_SIZE=50000000
#
# Fonction d'aide
#
usage() {
cat <<EOF
Usage :
$0 -h
$0 [-w warning_nb_mails] [-c critical_nb_mails] [-W warning_size] [-C critical_size]
Valeurs par défaut:
warning_nb_mails: $WARNING_REQ
critical_nb_mails: $CRITICAL_REQ
warning_size: $WARNING_SIZE
critical_size: $CRITICAL_SIZE
EOF
}
#
# Gestion des paramètres
#
while getopts hw:c:W:C: f; do
case "$f" in
'h')
usage
exit
;;
'w')
WARNING_REQ="$OPTARG"
;;
'c')
CRITICAL_REQ="$OPTARG"
;;
'W')
WARNING_SIZE="$OPTARG"
;;
'C')
CRITICAL_SIZE="$OPTARG"
;;
\?)
usage
exit 1
;;
esac
done
#
# Lancement de la commande
#
RESULT=$( $COMMANDE | grep -v "^[^A-Za-z0-9]" | grep -v "^[[:space:]]" | awk '{ print $2 }' )
# ... et analyse de la sortie
if [ -z "$RESULT" ]; then
# Queue vide
REQ=0
SIZE=0
else
REQ=$( echo "$RESULT" | wc -w )
SIZE=0
for i in $RESULT; do
SIZE=$(( $SIZE + $i ))
done
fi
#
# Analyse des résultats
#
if [ "$SIZE" -ge "$CRITICAL_SIZE" ] || [ "$REQ" -ge "$CRITICAL_REQ" ]; then
RETURN_STATUS=2
printf "CRITICAL ($REQ mail(s) in queue for $SIZE byte(s))"
else
if [ "$SIZE" -ge "$WARNING_SIZE" ] || [ "$REQ" -ge "$WARNING_REQ" ]; then
RETURN_STATUS=1
printf "WARNING ($REQ mail(s) in queue for $SIZE byte(s))"
else
RETURN_STATUS=0
printf "OK ($REQ mail(s) in queue for $SIZE byte(s))"
fi
fi
printf " | req=%d;%d;%d size=%dB;%d;%d\n" "$REQ" "$WARNING_REQ" "$CRITICAL_REQ" "$SIZE" "$WARNING_SIZE" "$CRITICAL_SIZE"
exit $RETURN_STATUS