Schedule and delete downtime automatically
Posted: Wed May 29, 2019 8:34 am
Hi, we plkan to schedule an downtime and delete the downtime automatically. We are using windows servers.
the best thing i was able to do was to create hoist groups, and then use the curl and date implementation from cygwin.
So my script is:
Running the script is:
schedule-downtime.cmd devsystem Testdowntime
This works perfect. All hosts and services in the devsystem hostgroup are now in downtime mode for 2 minutes.
Now I want to finish the downtime for a complete hostgroup. How can I do this?
The documentation tells me that deleting a downtime requires the following info:
the best thing i was able to do was to create hoist groups, and then use the curl and date implementation from cygwin.
So my script is:
Code: Select all
echo set variables
set nagiosserver=https://servername
set apikey=gggxxxxxxxxxxxxxxxxxxxfffffffffffff
set hostgroups=%1
set comment=%2
if "%1"=="" goto :ERROR
if "%2"=="" goto :ERROR
echo set time
for /f %%i in ('D:\nagios-downtime\date1.exe +%%s') do set start_time=%%i
for /f %%j in ('D:\nagios-downtime\date1.exe +%%s -d "+2 Minutes"') do set finish_time=%%j
echo run program
echo D:\nagios-downtime\curl.exe --insecure -XPOST "%nagiosserver%/nagiosxi/api/v1/system/scheduleddowntime?apikey=%apikey%&pretty=1" -d "comment=%comment%&start=%start_time%&end=%finish_time%&hostgroups[]=%hostgroups%&all_services=1"
D:\nagios-downtime\curl.exe --insecure -XPOST "%nagiosserver%/nagiosxi/api/v1/system/scheduleddowntime?apikey=%apikey%&pretty=1" -d "comment=%comment%&start=%start_time%&end=%finish_time%&hostgroups[]=%hostgroups%&all_services=1"schedule-downtime.cmd devsystem Testdowntime
This works perfect. All hosts and services in the devsystem hostgroup are now in downtime mode for 2 minutes.
Now I want to finish the downtime for a complete hostgroup. How can I do this?
The documentation tells me that deleting a downtime requires the following info:
But the objects/downtime command gives me a list back with several information. How can I find out which IDs belong to a specific hostgroup?system/scheduleddowntime/<internal_id>
Deletes a scheduled downtime from the Nagios XI system. The downtime ID can be found in objects/downtime.