Nagios xi API Hostgroup members configuration.

This support forum board is for support questions relating to Nagios xi, our flagship commercial network monitoring solution.
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

Nagios xi API Hostgroup members configuration.

Post 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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios xi API Hostgroup members configuration.

Post 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.
dsynapalos
Posts: 23
Joined: Tue Jun 25, 2019 2:26 am

Re: Nagios xi API Hostgroup members configuration.

Post by dsynapalos »

Thank you, I was able to find my fault in the structure and the request worked correctly.
You may close the ticket.