Page 1 of 1

Removing a host free variable via the API

Posted: Mon Jul 09, 2018 12:19 pm
by krutaw
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.

Re: Removing a host free variable via the API

Posted: Mon Jul 09, 2018 4:10 pm
by tgriep
Thanks for the tip @krutaw.