Page 1 of 1

Creating host with hostgroups using Nagios XI REST api

Posted: Mon Jan 07, 2019 9:04 am
by WillemDH
Hello,

We have a need to add and synchronize hostgroups to hosts dynamically in Nagios XI, but we noticed this still isn't possible using the Nagios XI REST api? With an continuously changing environment, it's important that we can synchronize role hostgroups etc with our cmdb.

When would adding hosts with hostgroups be possible with the Nagios XI REST api?

Grtz

Willem

Re: Creating host with hostgroups using Nagios XI REST api

Posted: Mon Jan 07, 2019 12:58 pm
by cdienger
Tested on 5.5.8, adding a host with hostgroups:

curl -XPOST "http://nagios_xi/nagiosxi/api/v1/config/host?apikey=api_key&pretty=1" -d "host_name=testapihost&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1&hostgroups=group1%2Cgroup2"

%2C is a URL encoded comma and only needed if adding the host to multiple groups.

Re: Creating host with hostgroups using Nagios XI REST api

Posted: Tue Jan 08, 2019 6:13 am
by WillemDH
Haa Thanks, that seems to work indeed. Is it also possible to get all the hostgroups a host belongs to with the REST api?

Re: Creating host with hostgroups using Nagios XI REST api

Posted: Tue Jan 08, 2019 2:34 pm
by cdienger
There is:

curl -XGET "http://nagios_xi/nagiosxi/api/v1/objects/hostgroupmembers?apikey=api_key&pretty=1&host_name=hostname"