Page 1 of 1

Edit hosts with REST api

Posted: Mon Apr 18, 2016 6:07 am
Hi,

Is it possible to edit hosts via REST API?
We would have a need to add different contact group based on few factors, and doing that manually will be tedious job.

I have tried to do so with:

Code: Select all

curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/host?apikey=xxxxxxxxxxx&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&contact_groups=test_group_1&max_check_attempts=2&check_period=24x7&notification_interval=5&notification_period=24x7&applyconfig=1"
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/host?apikey=xxxxxxxxxxx&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&contact_groups=test_group_2&max_check_attempts=2&check_period=24x7&notification_interval=5&notification_period=24x7&applyconfig=1"
But in that the contact_group was not added either in the first place.

So is this anyway even possible?
My version of Nagios XI is 5.2.0

Re: Edit hosts with REST api

Posted: Mon Apr 18, 2016 12:34 pm
by lmiltchev
Currently, it is not possible to "edit" objects via the REST API. Every time you use the REST API command you are "recreating" the objects. So, if you want to add a second contact group to this host, you will need to add BOTH contact groups at the same time. Example:
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/h ... x&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&contact_groups=test_group_1,test_group_2&max_check_attempts=2&check_period=24x7&notification_interval=5&notification_period=24x7&applyconfig=1"