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?
Query each host and reports hostgroup membership
-
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
You have this correct, just need to know what to add to the query string
So the call would look like
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
&host_name=HOSTNAMECode: Select all
/nagiosxi/api/v1/objects/hostgroupmembers?apikey=APIKEY&pretty=1&host_name=HOSTNAMETo 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=PingRe: Query each host and reports hostgroup membership
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
See Help -> API Docs -> Objects Reference -> Building Limited Queries section
You can use the in: qualifier
You can use the in: qualifier
Code: Select all
&host_name=in:HOSTNAME1,HOSTNAME2Re: Query each host and reports hostgroup membership
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.
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
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:
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