Page 1 of 1

Nagios XI API Hostgroup members configuration.

Posted: Thu Mar 18, 2021 7:53 am
by dsynapalos
Hello and good day,

As per the documentation in the API Docs - Config Reference, we can use a PUT request to modify the alias of an existing Hostgroup

Sample cURL Request:

Code: Select all

curl -XPUT "https://.../nagiosxi/api/v1/config/hostgroup/testapihostgroup?apikey=...&pretty=1&alias=New Alias&applyconfig=1"
We would like to edit the members list property but the correct way to implement the request is not described in the documentation.

We have tryed the following requests to no success:

Code: Select all

curl -XPUT "https://.../nagiosxi/api/v1/config/hostgroup/testapihostgroup?apikey=...&pretty=1&members=member1&applyconfig=1"

Code: Select all

curl -XPUT "https://.../nagiosxi/api/v1/config/hostgroup/testapihostgroup?apikey=...&pretty=1&members=[member1]&applyconfig=1"

Code: Select all

curl -XPUT "https://.../nagiosxi/api/v1/config/hostgroup/testapihostgroup?apikey=...&pretty=1&members[]=member1&applyconfig=1"

Code: Select all

curl -XPUT "https://.../nagiosxi/api/v1/config/hostgroup/testapihostgroup?apikey=...&pretty=1&members[]=[member1]&applyconfig=1"
We have also tried PUT requests to the objects/hostgroupmembers endpoint without success.

Re: Nagios XI API Hostgroup members configuration.

Posted: Thu Mar 18, 2021 6:21 pm
by ssax
What XI version are you running?

I just tried these on both on mine and they worked:

NOTE: Make sure to change YOURHOSTGROUPNAME, YOURAPIKEY, HOST1

Code: Select all

curl -k -L -XPUT "https://X.X.X.X/nagiosxi/api/v1/config/hostgroup/YOURHOSTGROUPNAME?apikey=YOURAPIKEY&pretty=1&members=HOST1&applyconfig=1"

Code: Select all

curl -k -L -XPUT "https://X.X.X.X/nagiosxi/api/v1/config/hostgroup/YOURHOSTGROUPNAME?apikey=YOURAPIKEY&pretty=1&members=HOST1,HOST2&applyconfig=1"
Did you make sure that the testapihostgroup hostgroup exists first? POST is for creating new, PUT is for updating existing, and DELETE is for deleting.

Additionally, that will only update the hostgroup in Configure > Core Config Manger > Host Groups, it will not add it on the the Host in Configure > Core Config Manager > Hosts.

Note that it will replace all the members on it with whatever you pass in so if it currently has some you would need to first script out the GET to get the members and then use the PUT to grab the hosts from the GET and then add/modify them, and then submit them.

Re: Nagios XI API Hostgroup members configuration.

Posted: Mon Mar 22, 2021 7:50 am
by dsynapalos
Thank you, I was able to find my fault in the structure and the request worked correctly.
You may close the ticket.