Edit hosts with REST api

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
[email protected]
Posts: 8
Joined: Mon Apr 18, 2016 5:14 am

Edit hosts with REST api

Post by [email protected] »

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
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Edit hosts with REST api

Post 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"
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked