#!/bin/sh
#
# Originally written by Matthew Evans
# Edited and finalized by Ryan Ticer
#
debug="0"
# SecurScan base directory
ssdir="/cygdrive/c/SecurScan"
# Accounts to check, separated by spaces
accounts=`cd "$ssdir" && find . -maxdepth 1 -type d | egrep -v "^.$|Cache|Log|Sendout|status|Unreturnable" | sed -e 's/.\///g'`
# How many runs of this script should we keep data for and test against
testspan="5"
# If the the current number of files in a directory has grown more than
# $percent percent since $testspan runs ago, we will alert
percent="20"
# Directory to keep our statistics in
statsdir="/var/log/check_caches/"
# Create stats dir if it does not already exist
[ ! -d $statsdir ] && mkdir $statsdir
for account in $accounts
do
if (( $debug > "0" ))
then
echo account $account
fi
# Create stats dir for account if it does not already exist
[ ! -d $statsdir/$account ] && mkdir $statsdir/$account
for dir in SMTP_Cache Extractor/Cache SASI_Cache
do
# Step 1: Gather statistics
outfile=$statsdir/$account/`echo $dir | sed s+/+_+`
last_num_files=$( tail -n 1 $outfile )
find $ssdir/$account/$dir -type f | wc -l >> $outfile
### Limit our history to $testspan previous runs
tail -n $testspan $outfile > $outfile~
mv $outfile~ $outfile
# Step 2: Crunch numbers and alert if necessary
old_num_files=$( head -n 1 $outfile )
cur_num_files=$( tail -n 1 $outfile )
if (( $debug > "0" ))
then
echo " dir $dir"
echo " cur_num_files $cur_num_files"
echo " old_num_files $old_num_files"
echo " last_num_files $last_num_files"
fi
if (( $cur_num_files > $((last_num_files + (last_num_files * ($percent/100) ))) && $cur_num_files > $((old_num_files + (old_num_files * ($percent/100) ))) ))
then
# Determine what the problem could possibly be
case $dir in
SMTP_Cache)
reason="The Analyzer process may be stuck or not running";;
Extractor/Cache)
reason="The Parser process may not be running" ;;
SASI_Cache)
reason="Permanent storage may not be available" ;;
*)
reason="I'm not sure what's going on." ;;
esac
# Dump a message to the syslog
logger -t "$0" "($dir, $account) $reason."
fi
done
done