Page 1 of 1
Query each host and reports hostgroup membership
Posted: Tue Oct 01, 2019 12:29 pm
by acentek
I have a request from an EU that states they would like to generate a report to show all devices and their associated host groups.
I was looking at the API and thought that maybe the hostgroupmembers query would show what I am looking for, but nope. I would like to query for hosts and then display the services and hostgroups based on the host.
Is this possible?
Re: Query each host and reports hostgroup membership
Posted: Tue Oct 01, 2019 1:18 pm
by scottwilkerson
You have this correct, just need to know what to add to the query string
So the call would look like
Code: Select all
/nagiosxi/api/v1/objects/hostgroupmembers?apikey=APIKEY&pretty=1&host_name=HOSTNAME
Note, this will only show hosts as members as services are not members of hostgroups.
To query service groups members you would do the same
Code: Select all
/nagiosxi/api/v1/objects/servicegroupmembers?apikey=APIKEY&pretty=1&host_name=HOSTNAME&service_description=Ping
Re: Query each host and reports hostgroup membership
Posted: Wed Oct 02, 2019 5:59 am
by acentek
Ok i might have an idea on what you suggest. But is there anyway to query all hostname's instead of having to put each hostname one by one.
Re: Query each host and reports hostgroup membership
Posted: Wed Oct 02, 2019 6:36 am
by scottwilkerson
See Help -> API Docs -> Objects Reference -> Building Limited Queries section
You can use the
in: qualifier
Re: Query each host and reports hostgroup membership
Posted: Mon Oct 14, 2019 9:22 am
by acentek
Ok so this does not look like it will generate the report that is being asked.
Here is what i am asking for. I can take the report and parse any data but apparently they want "hosts" and query for all associated hostgroups.
See below.
What I would like is a report of all devices and their associated host groups.
For example:
HOST hostgroup 1 hostgroup2 hostgroup 3 hostgroup 4
HSTBASCO01 Site- HSTN 00 Region – MN/IA Exchange – HSTN Device Type – Pannaway BAS [MN]
The reason for my request is that I am finding some devices which either have no host group or incorrect ones. I would like to review all devices and make sure they are all associated correctly.
Re: Query each host and reports hostgroup membership
Posted: Mon Oct 14, 2019 9:31 am
by scottwilkerson
The only way to do this would be to grab a list of all the hosts (for example wit
objects/host)
And then make another call for each host to the
objects/hostgroupmembers API to see what hostgroups (if any) that the host is a member of:
Code: Select all
/nagiosxi/api/v1/objects/hostgroupmembers?apikey=APIKEY&pretty=1&host_name=HOSTNAME