I couldn't find a way to do this with standard commands, so I wrote a little shell script to accomplish this.
I wanted to check my /var/log/auth.log to see if someone did a failed login.
I'm using the perl script 'logtail'
Only recently I found out it existed. Before I used my own script for that.
logtail keeps an offset-file and will only output the tail of a file it didn't show previously.
I did need to add it to the /etc/sudoers file
This is the line in /etc/zabbix/zabbix_agentd.conf:
/usr/local/sbin/regcount
I created this item
And this trigger:
I wanted to check my /var/log/auth.log to see if someone did a failed login.
I'm using the perl script 'logtail'
Only recently I found out it existed. Before I used my own script for that.
logtail keeps an offset-file and will only output the tail of a file it didn't show previously.
I did need to add it to the /etc/sudoers file
Code:
zabbix ALL=(ALL) NOPASSWD: /usr/sbin/logtail
Code:
UserParameter=vfs.file.regcount[*],/usr/local/sbin/regcount "$1" "$2"
Code:
#!/bin/bash
#####################################################
# regcount
# returns the occurences of a regular expression in
# a file since its last run
#####################################################
# Uses logtail & readlink
# http://sourceforge.net/projects/logtail/
#####################################################
# 08-12-2010 by Frater
#
# Use at your own risk!
#####################################################
export PATH=/usr/local/sbin:$PATH
[ ! -h "$1" ] && [ ! -f "$1" ] && exit 1
[ -z "$2" ] && exit 1
fname="`readlink -f "$1"`"
expression="`echo "$2" | tr -cd '0-9A-Za-z'`"
offset="/tmp/`basename "${fname}"`.${expression}.offset"
sudo logtail -f "$1" -o $offset | grep -ciE "$2"
exit $?
Code:
vfs.file.regcount[/var/log/auth.log,"Failed password for"] interval: 1200 numeric decimal
Code:
/var/log/auth.log shows failed SSH logins on server {HOSTNAME}
{Template_Linux:vfs.file.regcount[/var/log/auth.log,"Failed password for"].last(0)}>100
Comment