Modifying a host via the REST API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Matthew.Cary
Posts: 32
Joined: Fri Nov 10, 2017 11:43 am

Modifying a host via the REST API

Post by Matthew.Cary »

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.
krutaw
Posts: 60
Joined: Wed Jul 31, 2013 6:30 pm

Re: Modifying a host via the REST API

Post by krutaw »

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.
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.

Hope that helps! ;)
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: Modifying a host via the REST API

Post by lmiltchev »

@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!
krutaw
Posts: 60
Joined: Wed Jul 31, 2013 6:30 pm

Re: Modifying a host via the REST API

Post by krutaw »

krutaw wrote:
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.
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.

Hope that helps! ;)
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.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Modifying a host via the REST API

Post by npolovenko »

Thanks, @krutaw! That's a good note.
@Matthew.Cary, Let us know if you have any questions.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked