Customizing notifications

Mike Lindsey mike-nagios at 5dninja.net
Thu Feb 4 02:50:36 CET 2010


Chip Burke wrote:
> I have a request to “plain English”-ify my notifications. One item I 
> have been asked for is when the service state changes, to report the 
> duration of the previous service state.
> 
> Example: HTTP is now OK after 00:02:35 of down time.
> 
> Is there an easy way to do this? It seems Nagios doesn’t offer a Last 
> State Duration macro, so I am assuming this is going to be a matter of 
> some sort of custom scripting. Has anyone had experience with this sort 
> of thing?

Likely, your best option will be to set up an event handler script for 
that service.   If you already have event handlers configured, and you 
want this logic to run everywhere, consider setting up a script like 
this for your global event handler.

In the event handler, you will want to touch a file in /tmp based on the 
host, service, and state, whenever there's a hard state change.

Like, /tmp/localhost-load-ok...  You could even simplify if all you care 
is ok/not ok.

Then in your notification script, just check for the presence of those 
files, and do your date calculation by pulling the modification date out 
with stat (or script code, if your notification command isn't a chunk of 
bash).


Something like:

now=`date +%s`
if [ "${NAGIOS_LASTSSERVICESTATE}" == "OK"]
then
	time=`echo ${now} - ${filetime} | bc`
	filetime=`stat -f "%m" /tmp/localhost-load-notok`
else
	time=`echo ${now} - ${filetime} | bc`
	filetime=`stat -f "%m" /tmp/localhost-load-ok`
fi	

echo "${NAGIOS_SERVICE} is now ${NAGIOS_SERVICESTATE} after ${time} 
seconds."


You might want to flesh it out with some file-exists tests as well.

Good luck!

-- 
Mike Lindsey

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
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