Page 1 of 1
Nagios XI API Add/Remove Hosts in Hostgroups
Posted: Thu Mar 03, 2016 9:12 pm
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!
Re: Nagios XI API Add/Remove Hosts in Hostgroups
Posted: Fri Mar 04, 2016 12:21 pm
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¬ification_interval=5¬ification_period=24x7&hostgroups=HG&force=1&applyconfig=1"
Re: Nagios XI API Add/Remove Hosts in Hostgroups
Posted: Fri Mar 04, 2016 2:11 pm
by chilyard
Thanks for the quick response. Not elegant as I'd like, but totally doable.
Grazie.
Re: Nagios XI API Add/Remove Hosts in Hostgroups
Posted: Fri Mar 04, 2016 2:33 pm
by lmiltchev
I am glad I could help!
