Check if a service have been acknowledged

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
mon-team
Posts: 171
Joined: Thu Jun 28, 2012 9:22 am

Check if a service have been acknowledged

Post by mon-team »

Hello,
i'd like to know the service status relative to the acknowledgement state, simply... i need to know if a service is in an acknowledge state or not.
This information will be used in the event handler, so that i'll do different actions based on the ack state of the service.

I've seen that there is not a nagios core macro, and all the other related macros (eg: $SERVICEACKCOMMENT$ ) cannot be used to be passed to the event handler. ( I thought to use this one as a workaround, if there was an ack comment it meant that the service was acknowledged).

Is there a way to get this information?

Regards
Francesco
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Check if a service have been acknowledged

Post by ssax »

Since there are no macros available for this you would need to make your event handler script do the checking, you could use the API:

See here for examples:

https://YOURXISERVER/nagiosxi/help/api- ... hoststatus

https://YOURXISERVER/nagiosxi/help/api- ... vicestatus

I wrote this bash script that should give you everything you need, make sure to yum install jq before testing:

Code: Select all

#!/bin/bash
APIKEY='XXXXxxxxxxxYOURKEYHERExxxxxxxXXXX'
HOSTSTATUSAPIURL="http://YOURXISERVER/nagiosxi/api/v1/objects/hoststatus?apikey=$APIKEY&pretty=1"
SERVICESTATUSAPIURL="http://YOURXISERVER/nagiosxi/api/v1/objects/servicestatus?apikey=$APIKEY&pretty=1"
CURLBIN=$(which curl)
JQBIN=$(which jq)
EVENTTYPE='host'
HOSTNAME='localhost'
SERVICEDESC='SSH'

if [[ $EVENTTYPE == "host" ]]; then
        RESULT=$($CURLBIN --silent -k -L "$HOSTSTATUSAPIURL&name=$HOSTNAME" | $JQBIN -r '.hoststatus.problem_acknowledged')
        EXITCODE=$?
else

        RESULT=$($CURLBIN --silent -k -L "$SERVICESTATUSAPIURL&host_name=$HOSTNAME&name=$SERVICEDESC" | $JQBIN -r '.servicestatus.problem_acknowledged')
        EXITCODE=$?
fi

if [[ $RESULT -eq 1 ]]; then
        OUTPUT="HAS BEEN ACKED"
else
        OUTPUT="HAS NOT BEEN ACKED"
fi

echo $OUTPUT
exit $EXITCODE
mon-team
Posts: 171
Joined: Thu Jun 28, 2012 9:22 am

Re: Check if a service have been acknowledged

Post by mon-team »

Thank for your reply, and for the script!
Unfortunately we still have Nagios XI 2014R2.7, and we don't have the API.
But we are going to upgrade Nagios to the latest version, so your info are really useful!
Thanks!
Francesco
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Check if a service have been acknowledged

Post by scottwilkerson »

mon-team wrote:Thank for your reply, and for the script!
Unfortunately we still have Nagios XI 2014R2.7, and we don't have the API.
But we are going to upgrade Nagios to the latest version, so your info are really useful!
Thanks!
Francesco
Once upgraded the above should work.. Good luck!
Former Nagios employee
Creator:
ahumandesign.com
Get Your Chart
Locked