HI,
Our XI instance integrates with an Event Management system that does not recognize Nagios Downtime. We would like XI to toggle the "status" field in the remote system. Is it possible to have XI make an API call to the Event Management system whenever a monitored host enters or leaves Downtime? How would I approach this?
For example, let's say I schedule downtime for Host1 from 2:00 to 4:00. When 2:00 arrives and XI sends an email saying the host has entered a period of downtime, can that Downtime state trigger an action that would make an API call to the event management system? Could XI do this again when Downtime expires or is cancelled?
Would Event Handlers be used for this? Does anyone have examples to share?
Thanks,
Mark
Can I make an API call to another app when downtime starts?
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: Can I make an API call to another app when downtime star
Hi Mark,
See: Standard Macros in Nagios
For an example of how to make an event handler using these standard macros, please follow the tutorial in the guide below.
Introduction to Event Handlers
Let us know if you have more questions.
Benjamin
Normally, the downtime would cause a state change, so if that is the case you can use an event handler with the API call. There are two standard macros, $HOSTDOWNTIME$ and $SERVICEDOWNTIME$, that will return non-zero if the host or service is in scheduled downtime.Would Event Handlers be used for this? Does anyone have examples to share?
See: Standard Macros in Nagios
For an example of how to make an event handler using these standard macros, please follow the tutorial in the guide below.
Introduction to Event Handlers
Let us know if you have more questions.
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Can I make an API call to another app when downtime star
This will get us started. Thanks!
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: Can I make an API call to another app when downtime star
HI,
Your welcome! We'll keep this open if you have any other questions.
Your welcome! We'll keep this open if you have any other questions.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
osk.dthompson
- Posts: 16
- Joined: Tue Oct 18, 2016 2:58 pm
Re: Can I make an API call to another app when downtime star
benjaminsmith, I'm on mlangkau's team. I'm trying to get this working but when I put the server in downtime, it doesn't seem to trigger my event handler. Any ideas? Below is my event handler command. The command is a python script trying to grab the contents of the notification types $DOWNTIMESTART$ and $DOWNTIMEEND$
Thanks,
$USER1$/osk_event_handler -s $DOWNTIMESTART$ -e $DOWNTIMEEND$
Thanks,
$USER1$/osk_event_handler -s $DOWNTIMESTART$ -e $DOWNTIMEEND$
-
osk.dthompson
- Posts: 16
- Joined: Tue Oct 18, 2016 2:58 pm
Re: Can I make an API call to another app when downtime star
Here's what we're seeing in the logs when downtime is kicked off. It's calling a notification handler, not our even handler.
[1616677995] HOST DOWNTIME ALERT: server.domain.com;STARTED; Host has entered a period of scheduled downtime
[1616677995] HOST NOTIFICATION: username;server.domain.com;DOWNTIMESTART (UP);xi_host_notification_handler;OK - 0.0.0.0: rta 0.235ms, lost 0%
[1616677995] HOST NOTIFICATION: username;server.domain.com;DOWNTIMESTART (UP);xi_host_notification_handler;OK - 0.0.0.0: rta 0.235ms, lost 0%
[1616677995] HOST NOTIFICATION: username;server.domain.com;DOWNTIMESTART (UP);xi_host_notification_handler;OK - 0.0.0.0: rta 0.235ms, lost 0%
[1616677995] HOST DOWNTIME ALERT: server.domain.com;STARTED; Host has entered a period of scheduled downtime
[1616677995] HOST NOTIFICATION: username;server.domain.com;DOWNTIMESTART (UP);xi_host_notification_handler;OK - 0.0.0.0: rta 0.235ms, lost 0%
[1616677995] HOST NOTIFICATION: username;server.domain.com;DOWNTIMESTART (UP);xi_host_notification_handler;OK - 0.0.0.0: rta 0.235ms, lost 0%
[1616677995] HOST NOTIFICATION: username;server.domain.com;DOWNTIMESTART (UP);xi_host_notification_handler;OK - 0.0.0.0: rta 0.235ms, lost 0%
Re: Can I make an API call to another app when downtime star
I wasn't able to get this to work by defining the event handler on the hosts/services because the event handler only runs in these cases:
https://assets.nagios.com/downloads/nag ... dlers.html
I was able to get it to work by doing this:
Put this in /usr/local/nagios/libexec/if_downtime_toggle_host_status.sh:
- Note: You will need to edit the sections to do the toggling via whatever method you need to use
Then run these commands:
Then go to Configure > Core Config Manager > Commands:
- Edit the xi_host_notification_handler command
- Add this onto the end of it:
--hostdowntime=$HOSTDOWNTIME$
- Save an Apply Configuration
Then go to Admin > Manage Components > Global Event Handlers:
- Click the Notifications tab
- Under the Host Notification Handler Commands check Enable on the first one
- Use this for the Command:
Now test.
https://assets.nagios.com/downloads/nag ... dlers.html
I was able to get it to work by doing this:
Put this in /usr/local/nagios/libexec/if_downtime_toggle_host_status.sh:
- Note: You will need to edit the sections to do the toggling via whatever method you need to use
Code: Select all
#!/bin/bash
case "$1" in
DOWNTIMESTART)
# This is for when the host goes into downtime
# Put your code/command in here that toggles the status when the host starts downtime
;;
DOWNTIMEEND)
# This is if you want it to toggle anything on downtime end
# Checking if downtime level is 0 (which means no overlapping downtime)
if [[ $2 -eq 0 ]]; then
# Put your code/command in here that toggles the status on downtime end
fi
;;
esac
exit 0Code: Select all
chown apache.nagios /usr/local/nagios/libexec/if_downtime_toggle_host_status.sh
chmod ug+x /usr/local/nagios/libexec/if_downtime_toggle_host_status.sh- Edit the xi_host_notification_handler command
- Add this onto the end of it:
--hostdowntime=$HOSTDOWNTIME$
- Save an Apply Configuration
Then go to Admin > Manage Components > Global Event Handlers:
- Click the Notifications tab
- Under the Host Notification Handler Commands check Enable on the first one
- Use this for the Command:
Code: Select all
/usr/local/nagios/libexec/if_downtime_toggle_host_status.sh "%type%" "%hostdowntime%"