Hi,
I based my active response script that sends whois information about
an IP on the zabbix-alert.sh script.
Sometimes I had the problem that my mails sent no information about
the host and the alert level. Investigating the problem I found out
that I made a mistake in one of the grep commands that analyse the
alert.log file. I thought I made a mistake. A few moments ago I looked
into the zabbix-alert.sh and saw that the problem was already there.
The problem is in the following lines:
21 ALERTID=$4
.
.
.
48 # Getting alert time
49 ALERTTIME=`echo "$ALERTID" | cut -d "." -f 1`
50
51 # Getting end of alert
52 ALERTLAST=`echo "$ALERTID" | cut -d "." -f 2`
53
54 # Getting full alert
55 ALERTTEXT=`grep -A 10 "$ALERTTIME" $PWD/../logs/alerts/alerts.log |
grep -v ".$ALERTLAST: " -A 10 `
56
57 # Extract host (agent) name from alert.
58 HOSTNAME=`echo "$ALERTTEXT" | sed -n '1,1s/^.*\:[0-9][0-9]\:[0-9]
[0-9][^A-Za-z0-9_]*\([-A-Za-z0-9_]*\)\->.*$/\1/p'`
The parameter $ALERTID is the ID given to the script. From that the
ALERTTIME and ALERTLAST is extracted. The BUG is in line 55 where the
ALERTTEXT is extracted. If only the ALERTTIME is used there and
several alerts happen at the same time (happened to me) there are
several parts extracted from the alert.log file. The result is that
the the HOSTNAME and other later needed parameters could not be
extracted exactly.
The solution would be to change the line like this:
55 ALERTTEXT=`grep -A 10 "$ALERTID" $PWD/../logs/alerts/alerts.log |
grep -v ".$ALERTLAST: " -A 10 `
The $ALERTID should be used instead of $ALERTTIME. So there is only
one alert extracted from the alert.log file.
I've tested it on several machines with the same wrong result. After
that I changed it in my active response script send-whois.sh. It
should be changed in the zabbix-alert.sh script too.
If you are interested in my active response script send-whois.sh I
would be glad to share it with you.
Kind regards
Andre Pietsch