Page 1 of 1
about nagiosxi api
Posted: Fri May 25, 2018 3:18 am
by Olin
hi ,
I found nagiosxi provides REST API.
I want to create an new host an add it to the old hostgroup .
create an new host was done . but how to add it to the old hostgroup ?
can i do it use nagiosxi REST API ?
Re: about nagiosxi api
Posted: Fri May 25, 2018 8:27 am
by eloyd
The API is a growing thing. At this time, I don't think modifying host groups is in the code. I'd like to see it though, so I am looking forward to the reply from Nagios.
Re: about nagiosxi api
Posted: Fri May 25, 2018 10:47 am
by lmiltchev
Adding a new host to an old hostgroup can be easily done via the REST API, but there is one thing that you need to keep in mind. It's not a "modification" of the hostgroup config... It's more like "recreating it from scratch" if this makes any sense. If you have any existing hostgroup members, you must "re-add" them, along with the new member (the host you created).
Here's an example. I added a testapihost via the REST API simply by copying/pasting the command from the "REST API - Config Reference" section under the Help menu. Next I added this host to an existing hostgroup I have.
The hostgroup's config prior to adding the host:
Code: Select all
define hostgroup {
hostgroup_name sensors
alias Sensors
members AKCP SensorProbe2,EM08T
}
To add the new member to the "Sensors" hostgotup (the "testapihost" host), I ran:
Code: Select all
[root@main-nagios-xi ~]# curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/hostgroup?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "hostgroup_name=sensors&alias=Sensors&members=AKCP SensorProbe2,EM08T,testapihost&force=1&applyconfig=1"
{
"success": "Successfully added sensors to the system. Config applied, Nagios Core was restarted."
}
The hostgroup's config after adding the host:
Code: Select all
define hostgroup {
hostgroup_name sensors
alias Sensors
members AKCP SensorProbe2,EM08T,testapihost
}
Now, the old "sensors" group has 3 members:
example01.PNG
Hope this helps.
Re: about nagiosxi api
Posted: Tue May 29, 2018 1:53 am
by Olin
thank you
@lmiltchev and
@eloyd.
it 's work !
Re: about nagiosxi api
Posted: Tue May 29, 2018 8:38 am
by scottwilkerson
Glad to hear it is resolved!