Page 1 of 1

Can I make an API call to another app when downtime starts?

Posted: Mon Mar 22, 2021 5:45 pm
by mlangkau
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

Re: Can I make an API call to another app when downtime star

Posted: Tue Mar 23, 2021 1:56 pm
by benjaminsmith
Hi Mark,
Would Event Handlers be used for this? Does anyone have examples to share?
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.

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

Re: Can I make an API call to another app when downtime star

Posted: Wed Mar 24, 2021 9:57 am
by mlangkau
This will get us started. Thanks!

Re: Can I make an API call to another app when downtime star

Posted: Wed Mar 24, 2021 3:53 pm
by benjaminsmith
HI,

Your welcome! We'll keep this open if you have any other questions.

Re: Can I make an API call to another app when downtime star

Posted: Wed Mar 24, 2021 3:58 pm
by osk.dthompson
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$

Re: Can I make an API call to another app when downtime star

Posted: Thu Mar 25, 2021 8:56 am
by osk.dthompson
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%

Re: Can I make an API call to another app when downtime star

Posted: Thu Mar 25, 2021 3:30 pm
by ssax
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

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 0
Then run these commands:

Code: 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
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:

Code: Select all

/usr/local/nagios/libexec/if_downtime_toggle_host_status.sh "%type%" "%hostdowntime%"
Now test.