Page 1 of 1

Using REST API, how to clear host's hostgroup field

Posted: Sun Mar 25, 2018 1:35 pm
by toneill2000
I'm using the REST API operation POST config/host. In this POST, I want to empty out the hostgroup column for a given host. The problem I'm having is that when I send an empty string or null, the hostgroup value still remains on the host. How can I clear this value using the POST config/host operation?

I know I could create a "dummy" host group and assign it to that but I don't want to do that because it creates an extraneous hostgroup that I don't want. And, I would have to make this dummy hostgroup "active." Not ideal nor wanted if I can help it.

I know how to create custom endpoints so maybe someone could offer advice on how I could leverage that process so I can call my own endpoint and then use whatever methods are available within Nagios to remove all hostsgroups from a host. Any feedback is much appreciated. Thank you!
Todd

p.s., I wish there was good documentation on how to interact with Nagios once I have a custom endpoint. I have basic custom endpoints created but they only serve purposes of things like SELECT data from MySQL and return that. I'd like more advanced stuff like changing data in Nagios with my custom endpoint. Is there any documentation for that anywhere?

Re: Using REST API, how to clear host's hostgroup field

Posted: Mon Mar 26, 2018 3:47 am
by harimittapalli
Are you trying to modify existing host?

i wonder if there was any PATCH method to update the nagios object configuration with out POST method.

If not you can create custom endpoint to PATCH/Update the object config

Re: Using REST API, how to clear host's hostgroup field

Posted: Mon Mar 26, 2018 11:43 am
by scottwilkerson
You can set the the following in the URL to post

Code: Select all

hostgroups=null

Re: Using REST API, how to clear host's hostgroup field

Posted: Sat Mar 31, 2018 9:10 pm
by toneill2000
@scottwilkerson, yes, that works. I'm not sure why I didn't think of that. I'm all set and thank you for the post.
Todd

Re: Using REST API, how to clear host's hostgroup field

Posted: Sat Mar 31, 2018 9:11 pm
by toneill2000
harimittapalli wrote:Are you trying to modify existing host?

i wonder if there was any PATCH method to update the nagios object configuration with out POST method.

If not you can create custom endpoint to PATCH/Update the object config

@harimittapalli, do you have an example snippet of a custom endpoint that can patch or update and object? Just something simple to get me going would be great! Thanks.

Re: Using REST API, how to clear host's hostgroup field

Posted: Mon Apr 02, 2018 8:43 am
by scottwilkerson
toneill2000 wrote: @harimittapalli, do you have an example snippet of a custom endpoint that can patch or update and object? Just something simple to get me going would be great! Thanks.
The POST actually updates, but to blank a field you need to set to null