Scheduled Downtime Script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
aditya.c.anand
Posts: 56
Joined: Mon Mar 20, 2017 7:16 am

Scheduled Downtime Script

Post by aditya.c.anand »

Hello Team,

If we want to put hosts and it's related service checks under maintenance window(scheduled downtime) via CLI and not via GUI then which command needs to be executed?
Actually we wanted to do some automation as we receive multiple requests to put hosts and it's services under scheduled downtime mode.
Please help us with the background script or command via which we can achieve the same.

Regards,
Aditya Anand
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Scheduled Downtime Script

Post by lmiltchev »

You can schedule a downtime for hosts/services from the command line in Nagios XI via the REST API.

Example:

Code: Select all

[root@main-nagios-xi ~]# curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime?apikey=OYdoHa7JGoreQbKFjEGg0OWO8vurBkMFiYjf9pe57JieTjSsduLeCXi0s6L3puXL&pretty=1" -d "comment=Test downtime creation&start=1550586992&end=1550587592&hosts[]=localhost"
{
    "success": "Schedule downtime command(s) sent successfully.",
    "scheduled": {
        "hosts": [
            "localhost"
        ]
    }
}
You can review the REST API documentation in Nagios XI under the "Help" menu.
Be sure to check out our Knowledgebase for helpful articles and solutions!
aditya.c.anand
Posts: 56
Joined: Mon Mar 20, 2017 7:16 am

Re: Scheduled Downtime Script

Post by aditya.c.anand »

Hey Team,

How this downtime creation&start=1550586992&end=1550587592 are defined as was unable to get the same. If we want to place the downtime as start time : 2019-02-20 16:00:00
End time : 2019-02-20 18:00:00

then what parameter we will pass here.

Also at hosts[]=localhost , we can replace this local host with the desired server name and it will place the downtime accordingly correct?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Scheduled Downtime Script

Post by lmiltchev »

How this downtime creation&start=1550586992&end=1550587592 are defined as was unable to get the same. If we want to place the downtime as start time : 2019-02-20 16:00:00
End time : 2019-02-20 18:00:00

then what parameter we will pass here.
If you didn't want to schedule downtime immediately (now), but wanted to use specific start/end times, you would need to use epoch unix timestamps. Here's an online converter that you could use:

https://www.epochconverter.com/

You can find the timestamp by entering the "human" date for start/end time, and clicking on the "Human date to Timestamp" button.
Also at hosts[]=localhost , we can replace this local host with the desired server name and it will place the downtime accordingly correct?
Correct. You could have something like this:

Code: Select all

hosts[]=First Host&hosts[]=Second Host,&hosts[]=Third Host, etc.
example01.PNG
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
aditya.c.anand
Posts: 56
Joined: Mon Mar 20, 2017 7:16 am

Re: Scheduled Downtime Script

Post by aditya.c.anand »

One more query:

How to use : all_services integer 0 or 1 for all services on specified hosts

as we tried it like the below mentioned, but it didn't worked.

-bash-4.2$ curl --insecure -XPOST "https://172.25.45.171/nagiosxi/api/v1/s ... f&pretty=1" -d "comment=Test downtime creation&start=1550721600&end=1550736000&hosts[]=xxxx all_services=1"
{
"success": "Schedule downtime command(s) sent successfully.",
"scheduled": {
"hosts": [
"xxxx all_services=1"
]
}
}

Whereas when we tried it like the below mentioned , it worked properly but only for host

-bash-4.2$ curl --insecure -XPOST "https://172.25.45.171/nagiosxi/api/v1/s ... f&pretty=1" -d "comment=Test downtime creation&start=1550718000&end=1550732400&hosts[]=xxxx"
{
"success": "Schedule downtime command(s) sent successfully.",
"scheduled": {
"hosts": [
"xxxx"
]
}
}
-bash-4.2$

Please help here.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Scheduled Downtime Script

Post by lmiltchev »

You forgot to add "&" symbol between the hostname and "all_services"...
Change this:
curl --insecure -XPOST "https://172.25.45.171/nagiosxi/api/v1/s ... f&pretty=1" -d "comment=Test downtime creation&start=1550721600&end=1550736000&hosts[]=xxxx all_services=1"
to this:
curl --insecure -XPOST "https://172.25.45.171/nagiosxi/api/v1/s ... f&pretty=1" -d "comment=Test downtime creation&start=1550721600&end=1550736000&hosts[]=xxxx&all_services=1"
Did it work now?

This works for me:

Code: Select all

# curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime?apikey=OYdoHa7JGoreQbKFjEGg0OWO8vurBkMFiYjf9pe57JieTjSsduLeCXi0s6L3puXL&pretty=1" -d "comment=Test downtime creation&start=1550595532&end=1550596132&hosts[]=localhost&all_services=1"
{
    "success": "Schedule downtime command(s) sent successfully.",
    "scheduled": {
        "hosts": [
            "localhost"
        ],
        "services": {
            "localhost": [
                "ALL"
            ]
        }
    }
}
I can see in the GUI that all services on localhost are in scheduled downtime.
Be sure to check out our Knowledgebase for helpful articles and solutions!
johncwelch
Posts: 22
Joined: Mon Jun 15, 2015 8:04 am

Re: Scheduled Downtime Script

Post by johncwelch »

I would like to request that for the timestamps in this function, rather than forcing us to translate between unix epoch timestamps and human time, that perhaps something that is still an integer and better for the people writing the code be used, such as: 20190326095200

still an integer. But easier to tell that it's the 26th day of the third month of 2019 at 09:52:00

It saves the humans time, and makes the code vastly more readable. Probably cuts down on bugs from the human end.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Scheduled Downtime Script

Post by lmiltchev »

Thanks for the suggestion! We may put a litter helper/timestamp converter in the Help menu in the future. Please keep in mind that the decision to implement the enhancement is at the sole discretion of our development team.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked