#!/bin/sh # Host throttle script designed to send a maximum of x pages (set in variable $npages) every x minutes (set in variable $ctime - represented in seconds, ie. 600 is 5 # minutes). # Set Variables hist=/usr/local/nagios/var/pagehist storm=/usr/local/nagios/var/storm ctime=600 npages=5 time=$( date +%s) admin=nagios@localhost tmp=/tmp/tmp$$ # Setup Temporary File rm -f $tmp touch $tmp # Check for pagehist file if [ -f $hist ]; then wait else touch $hist fi # Purge entries older than x minutes from pagehist file ttime=`expr $time - $ctime` awk ' { if($0 > "'"$ttime"'") print $0} ' $hist > $tmp mv $tmp $hist # Have more than x pages been sent in the last x minutes - if yes then do not send page. pages=`echo \`wc -l < $hist\`` mins=`expr $ctime / 60` if [ "$pages" -ge "$npages" ]; then while read line do if [ "$line" -ne 1 ]; then echo 1 > $storm /bin/mail -s "More than $npages sent in $mins minutes" $8 exit 0 else exit 0 fi done < $storm else /usr/bin/printf "%b" "Host '$1' is $2\nInfo: $3\nTime: $4" | /bin/mail -s "$5 alert - Host $6 is $2" $8 echo "$time" >>$hist echo 0 > $storm fi # Clean Up rm -f $tmp