Page 1 of 1
Curl commands using REST API
Posted: Thu Oct 03, 2019 8:31 am
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 ?
Re: Curl commands using REST API
Posted: Thu Oct 03, 2019 8:42 am
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.
Re: Curl commands using REST API
Posted: Thu Oct 03, 2019 8:57 am
by bsivavani
Thanks for your help.
Can you provide similar command to remove host and all its services from maintenance mode.
Re: Curl commands using REST API
Posted: Thu Oct 03, 2019 10:23 am
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:
and run it:
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!
Re: Curl commands using REST API
Posted: Thu Oct 03, 2019 10:30 am
by vignesha
Hi,
Is there any possibility to add network devices like (switch,access point...,) by using CURL command?
Re: Curl commands using REST API
Posted: Thu Oct 03, 2019 10:34 am
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.