Hi Team,
Can you help with the script removal of hosts and along with services from scheduled Maintenance mode Using API from nagiosxi.
Thanks
Removal of hosts and service using API
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: Removal of hosts and service using API
Hi @mejokj,
You can use the API commands to do this. The API is fully documented in the GUI by going to Help > API Docs.
There are two parts to automating this task. In order to remove the scheduled downtime, it's necessary to retrieve the internal_id. You can get list of all the objects and their corresponding internal_id with using the following example command. Check the API docs for this by going to objects/downtime.
Then the following command System Command will remove scheduled downtime.
If you have a bunch of objects in schedule downtime, then you'll need to make a simple script to grab all the internal_ids and delete them.
Let me know if you have any questions about the API.
We don't really create custom scripts as part of product support. Below is an example you can use to help get you started.
Best Regards,
Benjamin
You can use the API commands to do this. The API is fully documented in the GUI by going to Help > API Docs.
There are two parts to automating this task. In order to remove the scheduled downtime, it's necessary to retrieve the internal_id. You can get list of all the objects and their corresponding internal_id with using the following example command. Check the API docs for this by going to objects/downtime.
Code: Select all
curl -XGET "https://192.168.23.113/nagiosxi/api/v1/objects/downtime?apikey=sCWXTQ3rHtm483AgRUUtLi04v5ECCVmktCCGoU8mINpPPflWafJbRKeGO8fGjUh6&pretty=1"
Code: Select all
curl -XDELETE "https://192.168.23.113/nagiosxi/api/v1/system/scheduleddowntime/10?apikey=sCWXTQ3rHtm483AgRUUtLi04v5ECCVmktCCGoU8mINpPPflWafJbRKeGO8fGjUh6&pretty=1"
Let me know if you have any questions about the API.
We don't really create custom scripts as part of product support. Below is an example you can use to help get you started.
Code: Select all
import requests
import json
ipaddress = '192.168.23.113'
apikey = 'sCWXTQ3rHtm483AgRUUtLi04v5ECCVmktCCGoU8mINpPPflWafJbRKeGO8fGjUh6'
data = requests.get("http://" + ipaddress + "/nagiosxi/api/v1/objects/downtime?apikey=" + apikey )
objects = json.loads(data.text)
ids = []
for item in objects['scheduleddowntime']:
ids.append(item['internal_id'])
data2 = {"query": {"match_all": {}}}
for id in ids:
delete_downtime = 'http://' + ipaddress + '/nagiosxi/api/v1/system/scheduleddowntime/' + id + '?apikey=' + apikey
r= requests.delete(delete_downtime, data=data2)
print('done')
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Removal of hosts and service using API
Hi Benjaminsmith,
Thanks for your feedback. We have a few more queries
Do we have any other way to remove the host/services from Scheduled Maintenance mode instead of getting object ID.
The attachment is collected Internal ID using API, but how we should know that this internal ID belongs to this host. I know in output hostname is showing like "host_name": "localhost".
Attachment is sent as PM to you.
Could you please make us clear instead of selecting internal_id do we have an option like if we give hostnames in one file which we need to removed from scheduled Maintenance mode based on that list, Nagios api should remove hosts/services from Scheduled Maintenance mode.
Thanks
Thanks for your feedback. We have a few more queries
Do we have any other way to remove the host/services from Scheduled Maintenance mode instead of getting object ID.
The attachment is collected Internal ID using API, but how we should know that this internal ID belongs to this host. I know in output hostname is showing like "host_name": "localhost".
Attachment is sent as PM to you.
Could you please make us clear instead of selecting internal_id do we have an option like if we give hostnames in one file which we need to removed from scheduled Maintenance mode based on that list, Nagios api should remove hosts/services from Scheduled Maintenance mode.
Thanks
-
benjaminsmith
- Posts: 5324
- Joined: Wed Aug 22, 2018 4:39 pm
- Location: saint paul
Re: Removal of hosts and service using API
Hi @mejokj,
For the system/scheduleddowntime endpoint, the internal id is required in order to delete the event.
However, it won't be too difficult to parse GET objects/downtime and grab all of the internal ids associated with a specific hostname by adding an extra step or check for that in your API script.
Best Regards,
Benjamin
For the system/scheduleddowntime endpoint, the internal id is required in order to delete the event.
However, it won't be too difficult to parse GET objects/downtime and grab all of the internal ids associated with a specific hostname by adding an extra step or check for that in your API script.
Best Regards,
Benjamin
You do not have the required permissions to view the files attached to this post.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Be sure to check out our Knowledgebase for helpful articles and solutions!