Removing a host free variable via the API
Posted: Mon Jul 09, 2018 12:19 pm
Just thought I'd share a tip, I ran across a need to remove a free variable from a host via the API. I wasn't able to find a good way to do so directly using commands in the API without simply replacing the host. So that's what I did.
In the scripting that we use for interfacing our ChatOps environment with Nagios XI, I already had code to allow for collecting the existing free variables so that it was additive instead when we would run that specific command. To that, I added code to detect when the value of a free variable is set to "-", and if so, eliminate it from the list of free variables. Then I simply add the host again with the list of free variables, hostgroups, etc. and voila. Free variable gone via the API.
In the scripting that we use for interfacing our ChatOps environment with Nagios XI, I already had code to allow for collecting the existing free variables so that it was additive instead when we would run that specific command. To that, I added code to detect when the value of a free variable is set to "-", and if so, eliminate it from the list of free variables. Then I simply add the host again with the list of free variables, hostgroups, etc. and voila. Free variable gone via the API.