Ecco la configurazione di swatch che sto utilizzando sui miei server per tenere d'occhio il demone vsftpd:
ignore /127.0.0.1/
#FTP File Status OK
watchfor /150/
echo
mail [email protected],subject=SWATCH HOME: FTP File Status OK
#FTP Command Not Implemented
watchfor /202/
echo
mail [email protected],subject=SWATCH HOME: FTP Command Not Implemented
#FTP User Logged Out
watchfor /221/
echo
mail [email protected],subject=SWATCH HOME: FTP User Logged Out
#FTP Directory Send OK
watchfor /226/
echo
mail [email protected],subject=SWATCH HOME: FTP Directory Send OK
#FTP User Logged In
watchfor /230/
echo
mail [email protected],subject=SWATCH HOME: FTP User Logged In
#FTP Requested File Action Ok
watchfor /250/
echo
mail [email protected],subject=SWATCH HOME: FTP Requested File Action Ok
#FTP Service Not Avaliable
watchfor /421/
echo
mail [email protected],subject=SWATCH HOME: FTP Service Not Available
#FTP Can't Open Data Connection
watchfor /425/
echo
mail [email protected],subject=SWATCH HOME: FTP Can't Open Data Connection
#FTP Transfer Aborted
watchfor /426/
echo
mail [email protected],subject=SWATCH HOME: FTP Transfer Aborted
#FTP File Unvailable
watchfor /450/
echo
mail [email protected],subject=SWATCH HOME: FTP File Unvailable
#FTP Command Unrecognized
watchfor /500/
echo
mail [email protected],subject=SWATCH HOME: FTP Command Unrecognized
#FTP Syntax Error
watchfor /501/
echo
mail [email protected],subject=SWATCH HOME: FTP Syntax Error
#FTP Command Not Implemented
watchfor /502/
echo
mail [email protected],subject=SWATCH HOME: FTP Command Not Implemented
#FTP Bad Sequence Of Commands
watchfor /503/
echo
mail [email protected],subject=SWATCH HOME: FTP Bad Sequence Of Commands
#FTP User Not Logged In
watchfor /530/
echo
mail [email protected],subject=SWATCH HOME: FTP User Not Logged In
#FTP Illegal File Name
watchfor /553/
echo
mail [email protected],subject=SWATCH HOME: FTP Illegal File Name
Come potete notare, le espressioni regolari verificano che all'interno del file /var/log/vsftpd.log siano presenti gli status code tipici del protocollo FTP.
Occorre precisare, però, che per default vsftpd non prevede il logging degli status code. Per abilitare tale funzione occorre modificare il file /etc/vsftpd.conf nel modo seguente:
xferlog_enable=YES
log_ftp_protocol=YES
xferlog_std_format=NO
A modifica completata riavviamo il demone in questione:
nightfly@nightbox:~$ sudo service vsftpd restart
ed infine inseriamo una entry nel file /etc/rc.local in modo da rendere automatica l'esecuzione di swatch per il monitoraggio di vsftpd ad ogni avvio del sistema:
swatch -c /etc/swatchftp.conf -t /var/log/vsftpd.log
Ora anche vsftpd può definirsi "sotto controllo".
Alla prossima.
PS: per una lista (semi)completa degli status code relativi al protocollo FTP, potete consultare questo link.