Well I found all the stuff for logwatch and it looked far too hard to deal with.
So I wrote a script based on logcheck.sh to do what I wanted.
Comments welcome. This is the very first script I've ever "published"
Assuming this ever gets out into the world at large, should I add my email address after my name? I have spamarrest on the account I was thinking of publishing, so it is unlikely to be a huge problem. But I'd appreciate advice just the same -- there are worse things than spammers.
Also do I need to add any more credits or disclaimers or anything?
Do I need to put something about GNU GPL somewhere (the original work was distributed under the GNU GPL). It is just a small silly little script after all - but I don't want to break any Rules.
NOTE: I disclaim EVERYTHING about this script. use at your own risk.
Code:
# mod_sec_Watch.sh: mod_security log file checker/mailer
# Written by Faris
#
# This script is based on:
# logcheck.sh Written by Craig Rowland
# which, along with logtail.c is based upon
# the frequentcheck.sh script idea from the Gauntlet(tm) Firewall
# (c)Trusted Information Systems Inc. The original authors are
# Marcus J. Ranum and Fred Avolio.
# This is version 1.0 of mod_sec_Watch.sh 23/04/2005
# (the first release version)
# Use at your own risk. You have been warned.
# INSTALLATION:
#
# 1) DO THIS FIRST:
# mkdir /usr/local/etc/modsectmp
# chmod 700 /usr/local/etc/modsectmp
# (lower prives would be better!)
# 2) Now install mod_security and configure it to output its logs to
# /var/log/httpd/audit_log
#
# There are many howtos on mod_security but I can't recommend www.gotroot.com
# highly enough if you want to learn and get good rulesets.
# 3) install logcheck in order to get the logtail program
# 4) copy this script somewhere (chmod it 700) and have it execute daily via cron, ideally
# at one minute to midnight so the date in the email represents the
# past 24 hours
# 5) look at the following configuration parameters and change them as
# required (mostly only SYSADMIN needs to be changed if you are a RedHat 9
# user and probably other RedHat varients too.
# CONFIGURATION SECTION
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin
# Person to send log activity to.
SYSADMIN=you@your-email-address.com
# Full path to logtail program.
# This program is required to run this script and comes with the logcheck package.
LOGTAIL=/usr/local/bin/logtail
# Full path to SECURED (non public writable) /tmp directory.
# Prevents Race condition and potential symlink problems. I highly
# recommend you do NOT make this a publically writable/readable directory.
# You would also be well advised to make sure all your system/cron scripts
# use this directory for their "scratch" area.
# NOTE: the following dir should be the one you created in the DO THIS FIRST section.
TMPDIR=/usr/local/etc/modsectmp
# The 'mail' command. Most systems this should be OK to leave as is.
# If your default mail command does not support the '-s' (subject) command
# line switch you will need to change this command one one that does.
# The only system I've seen this to be a problem on are HPUX boxes.
# Naturally, the HPUX is so superior to the rest of UNIX OS's that they
# feel they need to do everything differently to remind the rest that
# they are the best ;).
#
# Linux, FreeBSD, BSDI, Sun, etc.
MAIL=mail
# HPUX 10.x and others(?)
#MAIL=mailx
# Digital OSF/1, Irix
#MAIL=Mail
# Shouldn't need to touch these...
HOSTNAME=`hostname`
DATE=`date +%m/%d/%y:%H.%M`
# Before we begin, remove any temporary files that may somehow have
# been left over, and if we can't delete them email an alert to
# the sysadmin
umask 077
rm -f $TMPDIR/check.$$
if [ -f $TMPDIR/check.$$ ]; then
echo "mod_sec_Watch temporary Audit Log files in $TMPDIR directory cannot be removed.
This may be an attempt to spoof the log checker." \
| $MAIL -s "mod_sec_Watch: $HOSTNAME - POSSILE PROBLEM ON $DATE" $SYSADMIN
exit 1
fi
## OK, first things first. Get audit log info and put in temp dir
# CHANGE path to wherever you told mod_security to put logs
$LOGTAIL /var/log/httpd/audit_log >> $TMPDIR/check.$$
# See if the tmp file exists and actually has data to check,
# if it doesn't we should erase it and exit as our job is done.
#
# If you don't want to be emailed if there are no
# new entries then just remove the two lines relating to
# emailing. (starting echo and | )
if [ ! -s $TMPDIR/check.$$ ]; then
rm -f $TMPDIR/check.$$
echo "Audit Log contained no new data" \
| $MAIL -s "mod_sec_Watch: $HOSTNAME - Audit Log is empty on $DATE" $SYSADMIN
exit 0
fi
# logically speaking, if we get to this point then there's data to be sent!
# we should therefore email them to sysadmin
cat $TMPDIR/check.$$ | $MAIL -s "mod_sec_Watch: $HOSTNAME - Audit Log on $DATE" $SYSADMIN
# OK, we emailed the log. Now remove the temp file.
rm -f $TMPDIR/check.$$
# that's it. the end.
#####################