Page 1 of 1

Check if a service have been acknowledged

Posted: Wed Jan 09, 2019 5:24 am
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

Re: Check if a service have been acknowledged

Posted: Wed Jan 09, 2019 1:18 pm
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

Re: Check if a service have been acknowledged

Posted: Thu Jan 10, 2019 3:14 am
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

Re: Check if a service have been acknowledged

Posted: Thu Jan 10, 2019 11:13 am
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!