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?
Using REST API, how to clear host's hostgroup field
-
toneill2000
- Posts: 29
- Joined: Sun Jan 14, 2018 12:56 pm
- Location: Madison, WI
-
harimittapalli
- Posts: 2
- Joined: Thu Aug 31, 2017 3:09 am
Re: Using REST API, how to clear host's hostgroup field
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
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
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Using REST API, how to clear host's hostgroup field
You can set the the following in the URL to post
Code: Select all
hostgroups=null-
toneill2000
- Posts: 29
- Joined: Sun Jan 14, 2018 12:56 pm
- Location: Madison, WI
Re: Using REST API, how to clear host's hostgroup field
@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
Todd
-
toneill2000
- Posts: 29
- Joined: Sun Jan 14, 2018 12:56 pm
- Location: Madison, WI
Re: Using REST API, how to clear host's hostgroup field
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.
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Using REST API, how to clear host's hostgroup field
The POST actually updates, but to blank a field you need to set to nulltoneill2000 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.