Nagios + SMS = TRUE?
James Turnbull
james at lovedthanlost.net
Thu Oct 2 13:00:05 CEST 2003
Mark Ferlatte wrote:
> James Turnbull said on Fri, Sep 26, 2003 at 10:59:18AM +1000:
>>> 5 pages in 5 minutes; any more than that, we don't send them, and
>>> just send
> Not at all. You'll have to hack it into shape for your installation;
> it definately falls into the hack category.
>
> If I get a chance, I'm going to clean it up so that I can use it in
> other places, but that seems less likely with each day. :)
Not being a python person I re-wrote Mark Ferlatte's script as a (very
crude)
simple shell script hack - emphasis on the hack. Thanks to Mark for the
inspiration.
I changed the host-notify-by-epager command to the following:
# 'host-notify-by-epager' command definition
define command{
command_name host-notify-by-epager
command_line /usr/local/nagios/bin/hthrottle "$HOSTALIAS$"
"$HOSTSTATE$" "$OUTPUT$" "$DATETIME$" "$NOTIFICATIONTYPE$" "$HOSTNAME$"
"$HOSTSTATE$" "$CONTACTPAGER$"
}
This calls this script:
#!/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
ctime=600
npages=5
time=$( date +%s)
admin=nagios at 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 five minutes - if yes then do
not send page.
pages=`echo \`wc -l < $hist\``
if [ "$pages" -ge "$npages" ]; then
/bin/mail -s "More than $npages pages sent in the last five minutes"
$admin
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
fi
# Clean Up
rm -f $tmp
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list