I’m trying to retrieve the hosts that are members of specific HostGroups using the Icinga Director API from Python (3.x) code
I found documentation that shows how to retrieve host(s) or hostgroup(s), however I would like to retrieve a hostgroup and only it’s members in one call to the Director API.
Is this possible?
Best regards.
My Icinga environment:
- Icinga 2 version (2.12.4):
- Ubuntu 24.04.2 LTS
- Apache/2.4.58 ,PHP 8.3.6
- Icinga Web 2 version and modules (2.12.4):
- Loaded Modules
director 1.11.5
doc 2.12.4
icingadb1.1.3
graphite -1.2.4
incubator 0.22.0
pdfexport 0.10.2
Depending on the amount of hosts that you are having in icinga director it might be easier to iterate over hosts and match the group:
If your hostgroup is from a template inheritance you can try:
director/hosts&resolved
the example in the docs is only for a direct fetch via
director/host?name=hostname.example.com&resolved
this might work for inheritance but not for apply rules.
another approach I would consider is to use icinga2 api to filter for hostgroups.
this gives me the hostnames that match the filter of all applied and directly and indirectly attached hostgroups.
with the list of the hostnames you can query icinga director api individually, fetch and update data.
As I’m writing this I think the second approach is much better.