Getting SMS alerts for critical log entries

I have previously been having some issues on my firewall wich I wanted to monitor more closely for, so I use the following script to send me an SMS notice when an error marked as “user.critical” has occured.


#!/bin/sh
# Simple script to check for any critical errors in the syslog.
# (C) Henrik Andersén 130105 14:24
# version 0.3
#Thanks to mr Almen for fixing my chronic temporary brain damage using parts of date.

LOG="/var/log/ext-firewall.log"
SMSTO=01234567890
SMSMSG="ALERT! A critical error has ocurred on host.domain!"
SMSAUTHHASH="auth-hash-here"
TODAY=`date +"%b %e"`

grep "${TODAY}" ${LOG} | grep "user.crit" > /dev/null
OUT=$?

if [ ${OUT} -eq 0 ] ; then
MATCH="TRUE"
else
MATCH="FALSE"
fi

if [ "${MATCH}" = "TRUE" ] ; then
echo "Sending SMS to notify about critical error in log."
fetch -q -o $$.sms "http://123.123.1.123/sms/API/0.2/send.php?h=${SMSAUTHHASH}&r=${SMSTO}&m=${SMSMSG}"
rm $$.sms
fi

exit 0

This is run via cron on a regular interval and lets me know when something happens that I want to look into.
There are a couple of things that could (should..) be done in a different way or simply polished, but it gets the job done.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *