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 ?
about nagiosxi api
Re: about nagiosxi api
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.
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Re: about nagiosxi api
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:
To add the new member to the "Sensors" hostgotup (the "testapihost" host), I ran:
The hostgroup's config after adding the host:
Now, the old "sensors" group has 3 members:
Hope this helps.
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
}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."
}Code: Select all
define hostgroup {
hostgroup_name sensors
alias Sensors
members AKCP SensorProbe2,EM08T,testapihost
}You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: about nagiosxi api
Glad to hear it is resolved!