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 ?
Curl commands using REST API
Re: Curl commands using REST API
You can schedule downtime for a host and all its services via the REST API simply by running a command like the one below:
In the GUI:
You can review the REST API documentation under the Help menu in Nagios XI.
Hope this helps.
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"
]
}
}
}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!
Re: Curl commands using REST API
Thanks for your help.
Can you provide similar command to remove host and all its services from maintenance mode.
Can you provide similar command to remove host and all its services from maintenance mode.
Re: Curl commands using REST API
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:
and grab the values of "internal_id" lines. Then, using these values, you could delete each downtime (one-by-one) by running:
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
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!
Code: Select all
curl -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/downtime?apikey=xxx&pretty=1"Code: Select all
curl -XDELETE "http://x.x.x.x/nagiosxi/api/v1/system/scheduleddowntime/<internal_id>?apikey=xxx&pretty=1"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"
doneCode: Select all
chmod +x /tmp/delete_downtimes.shCode: Select all
cd /tmp
./delete_downtimes.shNote: 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!
Re: Curl commands using REST API
Hi,
Is there any possibility to add network devices like (switch,access point...,) by using CURL command?
Is there any possibility to add network devices like (switch,access point...,) by using CURL command?
Re: Curl commands using REST API
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!