96 lines
1.5 KiB
Bash
Executable file
96 lines
1.5 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
COMMANDE="/usr/sbin/postqueue -p"
|
|
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 [ "x$RESULT" = "xqueue" ]; 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"
|
|
else
|
|
if [ "$SIZE" -ge "$WARNING_SIZE" ] || [ "$REQ" -ge "$WARNING_REQ" ]; then
|
|
|
|
RETURN_STATUS=1
|
|
printf "WARNING"
|
|
else
|
|
RETURN_STATUS=0
|
|
printf "OK"
|
|
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
|