Richard Bruno
navigation
Home
admin









Swatch
October 18th, 2016

Table des matières


Installation
Configuration
Script de démarrage


Installation



Sur debian, c'est facile !

apt-get install swatch



Configuration



Docs

man swatch


En ligne : http://linux.die.net/man/1/swatch

threshold

threshold permet de configurer des alertes lorsque des paliers sont atteints...

"limit : Perform action(s) for the first "count" matches during the time interval specified by "seconds", then ignore events for the rest of the time interval (kind of like throttle)"
Ainsi

threshold track_by='AUTHENTICATION_FAILED',type=limit,count=2,seconds=60


permet de déclencher des alertes lorsque la chaine 'AUTHENTICATION_FAILED' a été trouvée dans les logs. Seules deux alertes seront déclenchées par minute.

"threshold : Perform action(s) on each match for up to count matches during the time interval specified by seconds"
Ainsi

threshold track_by='AUTHENTICATION_FAILED',type=threshold,count=20,seconds=120


permet de déclencher une alerte lorsque la chaine 'AUTHENTICATION_FAILED' a été trouvée 20 fois dans les logs pendant les 120 dernières secondes.
Note : si la chaine est retrouvée 20 fois pendant ces mêmes 120 secondes, une seconde alerte est générée.

"both : Perform actions(s) once per time interval after "count" matches occur, then ignore additional matches during the time interval specified by "seconds"
Ainsi :

threshold track_by='AUTHENTICATION_FAILED',type=both,count=20,seconds=120


permet de déclencher une alerte lorsque la chaine 'AUTHENTICATION_FAILED' a été trouvée 20 fois dans les logs pendant les 120 dernières secondes.
Note : l'option both déclenche une seule alerte / 120 secondes.

avec l'option track_by=key, key doit être entouré de simples quotes (') et non de doubles (") sinon
on risque des erreurs du genre :

tring found where operator expected at /root/.swatch_script.3888 line 97, near ""AUTHENTICATION_SUCCESS"", 'MESSAGE' => ""
(Missing operator before ", 'MESSAGE' => "?)
Scalar found where operator expected at /root/.swatch_script.3888 line 97, near "", 'MESSAGE' => "$_"
(Missing operator before $_?)



mail

Je n'ai pas réussi à faire fonctionner cette option de manière satisfaisante : les mails arrivent par paquets.
J'ai utilisé à la place l'option exec.

Exemple

watchfor /AUTHENTICATION_FAILED/

# 3 erreurs en deux minutes
threshold track_by='AUTHENTICATION_FAILED',type=both,count=2,seconds=120
# echo red
exec echo `date` |mail -s "FAILED" bruno...@univ-lemans.fr



Script de démarrage


# cat /etc/init.d/swatch
#!/bin/sh
### BEGIN INIT INFO
# Provides: swatch
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
#
# Startup script for swatch daemon on Debian
# B. Richard 06 2012
# Université du Maine
#
case "$1" in
start)
echo "Starting swatch daemon"
/usr/bin/swatch -c /etc/swatch.conf -t /usr/local/tomcat/logs/auth.log --daemon
echo
;;
stop)
echo "Stopping swatch daemon"
pkill -f /usr/bin/swatch
echo
;;
*)
echo "Usage: swatch {start|stop}"
exit


esac







Dernières modifs
Divers (October 18th, 2016)
ElasticSearch (October 18th, 2016)
Les portables et leurs batteries (October 18th, 2016)
Munin (October 18th, 2016)
Nagios (October 18th, 2016)
OpenManage (October 18th, 2016)
Rkhunter (October 18th, 2016)

Contact
Pour m'envoyer un mail,
Pour me laisser un commentaire :
richard.brunooo
chez
gmail.com


powered by kure, modified by Bruno