Curl commands using REST API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Curl commands using REST API

Post by bsivavani »

Hi,

We are using Nagios XI 5.6.5 and looking for below curl commands using REST API
1) To place host in scheduled downtime
2) To place all services tagged to that host in scheduled downtime

Kindly advice ?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Curl commands using REST API

Post by lmiltchev »

You can schedule downtime for a host and all its services via the REST API simply by running a command like the one below:

Code: Select all

curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime?apikey=xxx&pretty=1" -d "comment=Test downtime creation&start=1570109855&end=1570110455&hosts[]=localhost&all_services=1"
{
    "success": "Schedule downtime command(s) sent successfully.",
    "scheduled": {
        "hosts": [
            "localhost"
        ],
        "services": {
            "localhost": [
                "ALL"
            ]
        }
    }
}
In the GUI:
example01.PNG
You can review the REST API documentation under the Help menu in Nagios XI.

Hope this helps.
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!
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Re: Curl commands using REST API

Post by bsivavani »

Thanks for your help.

Can you provide similar command to remove host and all its services from maintenance mode.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Curl commands using REST API

Post by lmiltchev »

This one will be more complicated. There is no a REST API call that would delete the schedule downtime on the host and all services in bulk... Usually, you would first find the downtimes by running:

Code: Select all

curl -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/downtime?apikey=xxx&pretty=1"
and grab the values of "internal_id" lines. Then, using these values, you could delete each downtime (one-by-one) by running:

Code: Select all

curl -XDELETE "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime/<internal_id>?apikey=xxx&pretty=1"
where you substitute "<internal_id>" in the above command with the actual value.

This could be a tedious process, so I put together a bash script that you could run. This is just an example. It worked for me just fine. Feel free to modify it if needed.

delete_downtimes.sh

Code: Select all

#!/bin/bash

IDs=`curl -s -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/downtime?apikey=xxx&pretty=1" | grep internal_id | grep -o '[0-9]\+'`

for i in $IDs
do
  URL="http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime/"
  URL="$URL$i?apikey=xxx&pretty=1"
  curl -XDELETE "$URL"
done
Modify the script with the actual IP address and API key, place it in /tmp, make it executable:

Code: Select all

chmod +x /tmp/delete_downtimes.sh
and run it:

Code: Select all

cd /tmp
./delete_downtimes.sh
Let us know if this helped.

Note: This script will find ALL of the downtimes, and remove them. If you wanted to grab only downtimes for a specific host/service, you would need to either do this manually or modify the script. Thank you!
Be sure to check out our Knowledgebase for helpful articles and solutions!
vignesha
Posts: 115
Joined: Wed Oct 03, 2018 9:09 am

Re: Curl commands using REST API

Post by vignesha »

Hi,

Is there any possibility to add network devices like (switch,access point...,) by using CURL command?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Curl commands using REST API

Post by lmiltchev »

You can add hosts/services via the REST API. You can review the REST API documentation under the "Help" menu in XI. If you have a specific question, please start a new / separate thread.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked