Nagios XI API Add/Remove Hosts in Hostgroups

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
chilyard
Posts: 2
Joined: Fri Jan 08, 2016 3:23 pm

Nagios XI API Add/Remove Hosts in Hostgroups

Post by chilyard »

I can add/remove hosts in Nagios XI via the API, but it appears I cannot modify the hostgroup to include that host nor can I include a hostgroup during creation of the host itself.

I'm looking to do this all through the API, if possible.

I searched and found a relevant thread from a year ago, sounds like it wasn't possible in 2015...hoping for better news.

Thanks!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI API Add/Remove Hosts in Hostgroups

Post by lmiltchev »

Modifying a hostgroup via the REST API would mean "recreating" this hostgroup from scratch. It should be quite easy to do so. Let's say you have a hostgroup named "HG" with 3 members - "Host1", "Host2", and "Host3".

Code: Select all

define hostgroup {
	hostgroup_name                		HG
	alias                         		MyHostGroup
	members                       		Host1,Host2,Host3
	}
Now, you need to add one more member - "Host4". You could run something like this from the command line:

Code: Select all

curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/hostgroup?apikey=xxxx=1" -d "hostgroup_name=HG&alias=MyHostGroup&members=Host1,Host2,Host3,Host4&force=1&applyconfig=1"
To include a hostgroup during a host creation, you could run something like this:

Code: Select all

curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/host?apikey=xxxx=1" -d "host_name=Host5&address=x.x.x.x&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&hostgroups=HG&force=1&applyconfig=1"
Be sure to check out our Knowledgebase for helpful articles and solutions!
chilyard
Posts: 2
Joined: Fri Jan 08, 2016 3:23 pm

Re: Nagios XI API Add/Remove Hosts in Hostgroups

Post by chilyard »

Thanks for the quick response. Not elegant as I'd like, but totally doable.


Grazie.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI API Add/Remove Hosts in Hostgroups

Post by lmiltchev »

I am glad I could help! :)
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked