Nagios Acknowledge shell script

Nagios is often used in an environment where using or accessing its CGI-based web interface to ‘acknowledge’ alerts may be difficult or impossible.

I was in such a situation recently, where a Nagios was going to SMS me about an alert every 2 hours and I had no easy means to ‘acknowledge’ that event to the alerting Nagios.

So after some searching, I found this script which you can run on the Nagios host to acknowledge an alert or event on a Host configured to that Nagios:
Note: Change ACKNOWLEDGE_HOST_PROBLEM to ACKNOWLEDGE_SVC_PROBLEM if the acknowledgement is for a Nagios Service not a Host.
The the ack is for a Service, then the printf needs to include the Host;Service-description then the “;1;1;1;…..” text.
ie: you’ve got to add the Service Name that’s to be acknowledged in its own field separated by semi-colons after the Hostname is listed for a ACKNOWLEDGE_SVC_PROBLEM Nagios Ack.

# This is a sample shell script showing how you can submit the ACKNOWLEDGE_HOST_PROBLEM command
# to Nagios. Adjust variables to fit your environment as necessary.

now=`date +%s`

if [ "a$hosttoack" = "a" ]; then
echo ERROR: Need Nagios Host name to use in Ack
exit 1

/usr/bin/printf "[%lu] ACKNOWLEDGE_HOST_PROBLEM;$hosttoack;1;1;1;nagiosadmin;Down I know\n" $now > $commandfile

This script is for Nagios as installed from a Package for CentOS, so modify the printf and commandfile paths are needed if your Nagios is installed to different directory paths or on different Unix systems.

Please note that the “1;1;1” is specific to Nagios and means “;;” which are:
If the “sticky” option is set to 1, the acknowledgement will remain until the service returns to an OK state. Otherwise the acknowledgement will automatically be removed when the service or host changes state.
If the “notify” option is set to 1, a notification will be sent out to contacts indicating that the current problem has been acknowledged.
If the “persistent” option is set to 1, the comment given with the acknowledgement will persist across restarts of Nagios. If not, the comment will be deleted the next time Nagios restarts.

Finally, the “nagiosadmin” is an ‘‘ or username relevant to Nagios and commonly is nagiosadmin and the text “Down I know” is variable and can also be changed to suit.

This entry was posted in Network Presence and tagged , , . Bookmark the permalink.