lunes, 23 de diciembre de 2013

Script que testea intentos fallidos de SSH

Script en Bash: 
#!/bin/bash
# Script que testea intentos fallidos de
# 0=OK
# 1=WARNING
# 2=CRITICAL
# 3=UNKNOWN
HOY=`date "+%b %d"`
LOG=/var/log/auth.log
CANT_FALLIDOS=`cat $LOG |grep "Authentication failed"|grep "$HOY" | wc -l`
if [ $CANT_FALLIDOS -gt 15 ]; then
{
 echo "CRITICAL - Intentos fallidos:$CANT_FALLIDOS";
 exit 2;
}
fi
if [ $CANT_FALLIDOS -gt 10 ]; then
{
 echo "WARNING - Intentos fallidos:$CANT_FALLIDOS";
 exit 1;
}
fi
echo "OK - Intentos fallidos:$CANT_FALLIDOS";
exit 0;

Monitoreamos NRPE, editamos el services.cfg del server de nagios:

vi /etc/nagios/services.cfg
define service{
use                             generic-service
host_name                  ar-stf-vm-xen-1-crp-3
service_description     SSH_Fail_Login
check_command        check_nrpe!check_ssh_auth
}

Editamos en el server que queremos monitorear el nrpe.conf y luego reiniciamos el servicio:

vi /usr/local/apps/nagios/etc/nrpe.cfg
command[check_ssh_auth]=/usr/local/apps/nagios/libexec/check_ssh_auth