Query each host and reports hostgroup membership

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
acentek
Posts: 123
Joined: Thu Jul 27, 2017 2:00 pm

Query each host and reports hostgroup membership

Post 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?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Query each host and reports hostgroup membership

Post by scottwilkerson »

You have this correct, just need to know what to add to the query string

Code: Select all

&host_name=HOSTNAME
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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
acentek
Posts: 123
Joined: Thu Jul 27, 2017 2:00 pm

Re: Query each host and reports hostgroup membership

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Query each host and reports hostgroup membership

Post by scottwilkerson »

See Help -> API Docs -> Objects Reference -> Building Limited Queries section

You can use the in: qualifier

Code: Select all

&host_name=in:HOSTNAME1,HOSTNAME2
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
acentek
Posts: 123
Joined: Thu Jul 27, 2017 2:00 pm

Re: Query each host and reports hostgroup membership

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Query each host and reports hostgroup membership

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked