Help with scheduleddowntime via API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Help with scheduleddowntime via API

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Help with scheduleddowntime via API

Post 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"
            ]
        }
    }
}
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Re: Help with scheduleddowntime via API

Post 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?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Help with scheduleddowntime via API

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Re: Help with scheduleddowntime via API

Post 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?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Help with scheduleddowntime via API

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Sampath.Basireddy
Posts: 252
Joined: Wed Dec 14, 2016 12:30 pm

Re: Help with scheduleddowntime via API

Post by Sampath.Basireddy »

Ok, Thank You @scottwilkerson.

Please close this topic.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Help with scheduleddowntime via API

Post by scottwilkerson »

Sampath.Basireddy wrote:Ok, Thank You @scottwilkerson.

Please close this topic.
Great!

Locking thread
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked