Page 1 of 1

Updating hostgroups via api

Posted: Fri Jul 26, 2019 9:02 am
by kmackay
Hi:

I'm attempting to update a hostgroup (adding 'simon.blah.com' to the 'Elasticsearch-servers' hostgroup via the api using the following:
curl -XPUT "http://watcher/nagiosxi/api/v1/config/h ... lyconfig=1"

simon.blah.com is an actual host in our config and when I execute the above command, it says that it's successful but when I check in the interface, it still returns the same list of servers as before the 'update'?

Am I missing a parameter or is this even possible via the api?

Thanks!

Re: Updating hostgroups via api

Posted: Fri Jul 26, 2019 10:11 am
by scottwilkerson
You probably want to add the hostgroup to the host config.

Code: Select all

curl -XPUT "http://watcher/nagiosxi/api/v1/config/host/simon.blah.com?apikey=QclTD3pVVHWiN8Gt4EZYfjKhC5gfJgOPL9Ilrogm5sXREEkXuDVMcF44ZDjJanOU&pretty=1&hostgroups=Elasticsearch-servers&applyconfig=1"
Alternatively, you can add it to the hostgroup like you were doing but you would update the members field not the host_name field, key point being this will replace everything that is currently in the list, so you would need to pass all the existing members plus the new one

e.g.

Code: Select all

curl -XPUT "http://watcher/nagiosxi/api/v1/config/hostgroup/Elasticsearch-servers?apikey=QclTD3pVVHWiN8Gt4EZYfjKhC5gfJgOPL9Ilrogm5sXREEkXuDVMcF44ZDjJanOU&pretty=1&members=originalMember,originalMember2,originalMember3,simon.blah.com&applyconfig=1"