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
Check if a service have been acknowledged
Re: Check if a service have been acknowledged
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:
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
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
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
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Check if a service have been acknowledged
Once upgraded the above should work.. Good luck!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