In our ongoing quest to use the rest API to automate the provisioning of Nagios XI I have another question:
I understand how to add a host via the API, and I know how to delete a host via the API, but how does one *modify* a host? What if I want to use the API to add or remove a hostgroup from an existing host? Or change the Template it is using?
I don't seem to be able to find this in the documentation.
Modifying a host via the REST API
Re: Modifying a host via the REST API
Yup, we do it all the time, though probably not how you think. When we goto "modify" a host, we first make a call to read the host properties to build the necessary post data, and then append/replace the necessary bits that need to change. Then we simply post to add the host again on the nagios server where it lives (I have a small fleet of them.) When you re-add the host, it'll simply overwrite the existing host entry, keeping the same table ID's in the backend nagiosql database.Matthew.Cary wrote:In our ongoing quest to use the rest API to automate the provisioning of Nagios XI I have another question:
I understand how to add a host via the API, and I know how to delete a host via the API, but how does one *modify* a host? What if I want to use the API to add or remove a hostgroup from an existing host? Or change the Template it is using?
I don't seem to be able to find this in the documentation.
Hope that helps!
Re: Modifying a host via the REST API
@Matthew.Cary As krutaw mentioned, modifying via the REST API is possible by re-adding the host, overwrting the "old" object. Let us know if you have any more questions.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Modifying a host via the REST API
I forgot to mention that if you have multiple Nagios servers that you check to see which server a given host is monitored by before submitting the post so that you don't end up doing double the monitoring by accident. I literally wrote a "get_host" function for my chatops script that determines which of my 5 nagios servers a given server is monitored by so I don't accidentally duplicate effort.krutaw wrote:Yup, we do it all the time, though probably not how you think. When we goto "modify" a host, we first make a call to read the host properties to build the necessary post data, and then append/replace the necessary bits that need to change. Then we simply post to add the host again on the nagios server where it lives (I have a small fleet of them.) When you re-add the host, it'll simply overwrite the existing host entry, keeping the same table ID's in the backend nagiosql database.Matthew.Cary wrote:In our ongoing quest to use the rest API to automate the provisioning of Nagios XI I have another question:
I understand how to add a host via the API, and I know how to delete a host via the API, but how does one *modify* a host? What if I want to use the API to add or remove a hostgroup from an existing host? Or change the Template it is using?
I don't seem to be able to find this in the documentation.
Hope that helps!
-
- Support Tech
- Posts: 3457
- Joined: Mon May 15, 2017 5:00 pm
Re: Modifying a host via the REST API
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.