Skip to content

Instantly share code, notes, and snippets.

@ja-mf
Created September 13, 2012 20:02
Show Gist options
  • Save ja-mf/3717179 to your computer and use it in GitHub Desktop.
Save ja-mf/3717179 to your computer and use it in GitHub Desktop.
check_sendmail nagios.
1. Configurar el path para el maillog, setear MAILLOG en check_postfix y update_postfix_stats
2. Copiar archivos al directorio de plugins de nagios y bin
3. Dar permisos al usuario definido en nrpe.cfg para que pueda leer maillog
4. Agregar al crontab:
*/5 * * * * root /usr/local/bin/update_postfix_stats
#!/usr/local/bin/bash
# agregar al cron que escriba cada 5 minutos
# los archivos sendmail_in y sendmail_out
# es necesario cambiar el grupo de MAILLOG, para que
# el usuario nrpe (o el usuario definido en nrpe.cfg) pueda leerlo
# exit 2 - critical
# exit 1 - warning
# exit 0 - normal
# uso: check_sendmail -w nwarning -c ncritical
# n mails entrando/saliendo a la cola
MAILLOG=/var/log/maillog
while getopts "w:c:" opt
do
case $opt in
w) warning="$OPTARG"
;;
c) critical="$OPTARG"
;;
esac
done
LAST_IN=`cat /tmp/sendmail_in`
LAST_OUT=`cat /tmp/sendmail_sent`
LAST_REJECTED=`cat /tmp/sendmail_rejected`
CURRENT_IN=`grep -F from=< $MAILLOG | wc -l`
CURRENT_OUT=`grep -F stat=Sent $MAILLOG | wc -l`
CURRENT_REJECTED=`grep -F reject= $MAILLOG | wc -l`
TAIL_IN=`expr $CURRENT_IN - $LAST_IN`
TAIL_OUT=`expr $CURRENT_OUT - $LAST_OUT`
TAIL_REJECTED=`expr $CURRENT_REJECTED - $LAST_REJECTED`
echo -n "in: $TAIL_IN; out: $TAIL_OUT; "
echo -n "rejected: $TAIL_REJECTED | "
echo -n "in=$TAIL_IN; out=$TAIL_OUT; "
echo -n "rejected=$TAIL_REJECTED; "
echo -n "total_in=${CURRENT_IN}c; total_out=${CURRENT_OUT}c;"
if [ "$TAIL_IN" -ge "$critical" ] || [ "$TAIL_OUT" -ge "$critical" ]
then
exit 2
elif [ "$TAIL_OUT" -ge "$warning" ] || [ "$TAIL_OUT" -ge "$warning" ]
then
exit 1
fi
exit 0
#!/usr/local/bin/bash
MAILLOG=/var/log/maillog
grep -F "stat=Sent" $MAILLOG | wc -l > /tmp/sendmail_sent
grep -F "from=<" $MAILLOG | wc -l > /tmp/sendmail_in
grep -F "reject=" $MAILLOG | wc -l > /tmp/sendmail_rejected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment