Is there a single API that mimic the online transaction of Blackout all services ?
I am trying to script a startup /shutdown script that puts it in blackout when it is shutdown and not crashed and taken out when it comes back up.
I have enabled host, but seems to continue with services.
Thanks
Nagios Scripting
Re: Nagios Scripting
I wonder if the all_services paramater of the POST system/scheduleddowntime endpoint is what you're after?
It states:
It states:
0 or 1 for all services on specified hosts
Re: Nagios Scripting
There isn’t a single API call that behaves exactly like the web UI “blackout all services” action. Under the hood, Nagios handles this by scheduling downtime per object.
For what you’re trying to do, the usual approach is to use the external command interface and submit scheduled downtime for the host and its services on shutdown, then remove it on startup. Simply enabling host downtime won’t automatically suppress service alerts unless you explicitly schedule service downtime as well.
Take a look at SCHEDULE_HOST_DOWNTIME together with SCHEDULE_HOST_SVC_DOWNTIME (or loop over services) in your script. That should get you much closer to the behavior you see in the UI.
For what you’re trying to do, the usual approach is to use the external command interface and submit scheduled downtime for the host and its services on shutdown, then remove it on startup. Simply enabling host downtime won’t automatically suppress service alerts unless you explicitly schedule service downtime as well.
Take a look at SCHEDULE_HOST_DOWNTIME together with SCHEDULE_HOST_SVC_DOWNTIME (or loop over services) in your script. That should get you much closer to the behavior you see in the UI.
Re: Nagios Scripting
Testing showed that the all_services parameter of the system/scheduleddowntime REST API endpoint did what I expected (and, I believe, what OP is after?).
It placed all services on the target host in downtime as well. Running this (replacing the server IP, API key, hostname, timstamps, and comment with your own settings) will place both the host and all of it's services in downtime:
It placed all services on the target host in downtime as well. Running this (replacing the server IP, API key, hostname, timstamps, and comment with your own settings) will place both the host and all of it's services in downtime:
Code: Select all
curl -XPOST "<XI.machine.IP>/nagiosxi/api/v1/system/scheduleddowntime?apikey=<your.API.key>\
&pretty=1" -d "comment=Test downtime creation&start=1767974399&end=1767981599\
&hosts[]=localhost&all_services=1"