Hostgroup of hostgroups in Icinga 2 Director

Hi,

I have a issue when creating a hostgroup of hostgroups. I have created a hostgroup “Icinga 2 Master” it has two servers. Then I created a Hostgroup “Icinga 2 Backend” which has a hostgroup included (Icinga 2 Master)

In detail:
object HostGroup “hg_icinga2_master” {
display_name = “Icinga 2 Master”
assign where host.name == “ici2-m1.local” || host.name == “ici2-m2.local”
}

object HostGroup “hg_icinga2_backend” {
display_name = “Icinga 2 Backend”
assign where “hg_icinga2_master” in host.groups
}

After deployment, I see two servers in “Icinga 2 Master”, but “Icinga 2 Backend” stays empty. I would expect to see also two servers. It gets even more confusing, there are groups I can add, which will show up in “Icinga 2 Backend”.

Has anybody an explanation for this behavior, do I do something wrong?

BTW: I do not intend to only add one host group to the host group.

You assign rule will onlY match if you define the first group in the host object.

And if you have more then one host.name in an assign rule its better to use an array for the assign rule

Assign where host.name in [ "host1", "host2" ]

But better would be to add a custom variable to your backend hosts like

vars.backendtype = "master|satellite|database|..."

And then assign your second group with
assign where host.backendtype

Regards,
Carsten

1 Like

Hi Carsten

Thanks for the replay. I tried the first solution (host.name in) and it worked. But my Backend Group has been still empty. So I taged all my hosts (no, not really) and created the hostgroups with where … and now all hostgroups are empty. Since I have given my hosts multiple tags I tried “contains” insted of “=” and now it works.
Excellent!
Thanks a lot.
Cheers
cheko

1 Like