about nagiosxi api

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Olin
Posts: 50
Joined: Tue Dec 26, 2017 1:46 am

about nagiosxi api

Post 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 ?
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: about nagiosxi api

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: about nagiosxi api

Post 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.
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!
Olin
Posts: 50
Joined: Tue Dec 26, 2017 1:46 am

Re: about nagiosxi api

Post by Olin »

thank you @lmiltchev and @eloyd.

it 's work !
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: about nagiosxi api

Post by scottwilkerson »

Glad to hear it is resolved!
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked