Page 1 of 1
Help with scheduleddowntime via API
Posted: Thu Dec 05, 2019 12:40 am
by Sampath.Basireddy
Am trying to create scheduled downtime on a hostgroup via API, but the start and end times appears to be tricky. I used
https://currentmillis.com/ to convert date & time
(12/04/2019 17:20:00 to 12/04/2019 17:25:00) to millis and ran curl command.
Here is the command I executed to create downtime:
Code: Select all
curl -XPOST "https://nagiosxi.company.com/nagiosxi/api/v1/system/scheduleddowntime?apikey=<API KEY>&pretty=1" -d "comment=Test downtime creation&start=1575501600000&end=1575501900000&hostgroups[]=STG-Servers"
{
"success": "Schedule downtime command(s) sent successfully.",
"scheduled": {
"hostgroups": {
"STG-Servers": [
"HOSTS",
"SERVICES"
]
}
}
}
I don't see any downtime created in "Scheduled Downtime", but I do see comments against each host and service in that host group and it reads "
This host has been scheduled for fixed downtime from 08-29-51895 01:20:00 to 09-01-51895 12:40:00. Notifications for the host will not be sent out during that time period."
For some reason, it is taking very strange timeframe.
Please suggest if am doing something wrong here.
Thank You.
Re: Help with scheduleddowntime via API
Posted: Thu Dec 05, 2019 8:29 am
by scottwilkerson
You are using millis instead of timestamps so the numbers are off by 1000X
Here's a better site to use
https://www.epochconverter.com/
Code: Select all
curl -XPOST "https://nagiosxi.company.com/nagiosxi/api/v1/system/scheduleddowntime?apikey=<API KEY>&pretty=1" -d "comment=Test downtime creation&start=1575501600&end=1575501900&hostgroups[]=STG-Servers"
{
"success": "Schedule downtime command(s) sent successfully.",
"scheduled": {
"hostgroups": {
"STG-Servers": [
"HOSTS",
"SERVICES"
]
}
}
}
Re: Help with scheduleddowntime via API
Posted: Thu Dec 05, 2019 5:10 pm
by Sampath.Basireddy
Thanks
@scottwilkerson for the link and yes, it worked now.
Does the API allow to use regular date and timestamps or it accepts only epoch timestamp?
Also, when deleting a scheduled downtime, as per the API it needs "internal_id" and it appears each service on each host has a different "internal_id".
In my above post, the command I used was to create downtime on a hostgroup. Incase if I have to delete the downtime for entire hosts in that group, is there an easy way to do it via API?
Re: Help with scheduleddowntime via API
Posted: Thu Dec 05, 2019 5:30 pm
by scottwilkerson
Sampath.Basireddy wrote:Does the API allow to use regular date and timestamps or it accepts only epoch timestamp?
Only epoch timestamps
Sampath.Basireddy wrote:Also, when deleting a scheduled downtime, as per the API it needs "internal_id" and it appears each service on each host has a different "internal_id".
In my above post, the command I used was to create downtime on a hostgroup. Incase if I have to delete the downtime for entire hosts in that group, is there an easy way to do it via API?
You would need to get this ID by querying the
objects/downtime API
Re: Help with scheduleddowntime via API
Posted: Thu Dec 05, 2019 5:50 pm
by Sampath.Basireddy
Correct, I can get the internal_id by objects/downtime API. But the internal_id is unique for each service check on each host.
When creating downtime, it allows to create on a hostgroup, but when deleting, is there a way to delete downtime on the hostgroup?
Re: Help with scheduleddowntime via API
Posted: Thu Dec 05, 2019 5:54 pm
by scottwilkerson
Sampath.Basireddy wrote:Correct, I can get the internal_id by objects/downtime API. But the internal_id is unique for each service check on each host.
When creating downtime, it allows to create on a hostgroup, but when deleting, is there a way to delete downtime on the hostgroup?
No, unfortunately, you would need to remove them individually
Re: Help with scheduleddowntime via API
Posted: Thu Dec 05, 2019 6:42 pm
by Sampath.Basireddy
Ok, Thank You
@scottwilkerson.
Please close this topic.
Re: Help with scheduleddowntime via API
Posted: Fri Dec 06, 2019 9:37 am
by scottwilkerson
Sampath.Basireddy wrote:Ok, Thank You
@scottwilkerson.
Please close this topic.
Great!
Locking thread