Dans cet article, j'ai mis en place un check nagios pour snort plutot basique en bash qui fait plusieurs contrôle, le check que le service snort tourne, et le check du nombre d'évenements déclenchés par jour.
Pour cela, j'utilise la base SQL que snort met à jours.
1) Dans un premier temps, il faut crééer un user de monitoring sur MySQL qui accéde à la base de Snort :
grant select on snort.* to [email protected]'%' identified by 'passsnortmonitoring' ; flush privileges ;
#!/bin/bash STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 HOST='localhost' USER='usersnortmonitoring' PASS='passsnortmonitoring' DB='snort' REGEX='^[0-9]+$' SERVICE=$(ps aux | grep snort | grep -v grep) if [ "$?" -ne "0" ]; then echo "Sercice KO" exit $STATE_CRITICAL fi ERROR=$(echo "select count(*) from event where timestamp > now() - interval 1 day ;" | mysql -h $HOST -u $USER -p$PASS $DB | tail -n 1) if ! [[ $ERROR =~ $REGEX ]] ; then echo "error: Not a number" exit $STATE_UNKNOWN fi if [[ "$ERROR" > "$2" ]]; then echo "total alert: "$ERROR exit $STATE_CRITICAL fi if [[ "$ERROR" > "$1" ]]; then echo "total alert: "$ERROR exit $STATE_WARNING fi echo "total alert: "$ERROR exit $STATE_OK
command[check_snort]=/usr/lib/nagios/plugins/check_snort.sh 10 30