Adding a hostgroup to a host definition using REST API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
ddaluka
Posts: 35
Joined: Wed Apr 01, 2015 7:27 am

Adding a hostgroup to a host definition using REST API

Post by ddaluka »

Hi,

I have added few hosts in Nagiosxi and I have added hostgroups in the host definitions instead of adding them as a member in hostgroup definition. I now want to add another hostgroup to one of the hosts keeping its already added hostgroups intact.

I know I can do it from UI using manage hostgroups but can someone help me if there is a way to do it using command line? May be using REST API or Database query? I need it to put in a script.

I am OK to delete the hosts and recreate but I first need the list of already existing hostgroups in that host definition before deleting and recreating.

I have tried following REST API but it doesn't give hostgroups list in the output.

http://NagiosHost/nagiosxi/api/v1/objec ... v&pretty=1

Thanks for your help in advance.
vazudevan
Posts: 36
Joined: Fri Oct 21, 2016 4:52 am

Re: Adding a hostgroup to a host definition using REST API

Post by vazudevan »

I suppose you should be using object/hostgroup part of API instead..

this should list all your host groups.
http://nagioshost/nagiosxi/api/v1/objec ... v&pretty=1
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: Adding a hostgroup to a host definition using REST API

Post by tacolover101 »

check out this doc which you might find handy -
Nagios-Automating-with-Nagios-XI.pdf
You do not have the required permissions to view the files attached to this post.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Adding a hostgroup to a host definition using REST API

Post by tmcdonald »

Thanks for the input, folks! @ddaluka let us know if you have further questions.
Former Nagios employee
ddaluka
Posts: 35
Joined: Wed Apr 01, 2015 7:27 am

Re: Adding a hostgroup to a host definition using REST API

Post by ddaluka »

Hi All,

Thank you for your inputs. I have now managed to get this information from database as a list of hostgroups for a host and then recreating the hosts definition after appending new hostgroups using perl script.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Adding a hostgroup to a host definition using REST API

Post by mcapra »

Awesome! Did you have additional questions regarding this topic, or can we close this thread?
Former Nagios employee
https://www.mcapra.com/
ddaluka
Posts: 35
Joined: Wed Apr 01, 2015 7:27 am

Re: Adding a hostgroup to a host definition using REST API

Post by ddaluka »

Yes.. We can close this thread. Thanks for your support
Locked