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!
Nagios XI API Add/Remove Hosts in Hostgroups
Re: Nagios XI API Add/Remove Hosts in Hostgroups
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".
Now, you need to add one more member - "Host4". You could run something like this from the command line:
To include a hostgroup during a host creation, you could run something like this:
Code: Select all
define hostgroup {
hostgroup_name HG
alias MyHostGroup
members Host1,Host2,Host3
}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"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"Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Nagios XI API Add/Remove Hosts in Hostgroups
Thanks for the quick response. Not elegant as I'd like, but totally doable.
Grazie.
Grazie.
Re: Nagios XI API Add/Remove Hosts in Hostgroups
I am glad I could help! 
Be sure to check out our Knowledgebase for helpful articles and solutions!