Many-to-many relationships in Icinga2

So typically there are many-to-many relationships in an Icinga configuration most obviously between hosts and services.

It is possible to add a list of services to a host, or a list of hosts to a service, but both are suboptimal because to update the lists one has to look at several entries.

So in Icinga1 I used to have empty hostgroups, and then add them to hosts and services to link them, which makes maintaining configurations a lot easier. Fully described here:

Is there something similar possible in the Icinga2 syntax? If so please suggest how to do it.

you can use “service apply rules” and as a rule you can use a “hostgroup contains xyz”

apply Service "test" {
    import "someservice"

    assign where "test" in host.groups

}

Hi @Walex,

Thank you for sharing this. We use Icinga Director and it looks like it allows to do what you describe, and more.

Best regards, and welcome to the community,

Jean

you can use “service apply rules” and as a rule you can use a “hostgroup contains xyz”

Thanks, that is useful. Does that imply that I can have empty (without any hosts listed) hostgroup definitions and list the hostgroups of each host in the host definition?

I had considered using vars in a similar way instead of hostgroups, but I would prefer to use hostgroups.

yes, a host group can be empty

Little side note here:
Please do not use HostGroups to assign Services, in my experience these things should be separated.
HostGroups are best used to group host for display, I prefer to assign Services based on custom vars (called “data fields” in the director). This avoids some problem, with the restricted logic of hostgroups, which are basically a list of tags.
With custom vars you can build something like exclusive fields ("this host is running a linux kernel OR a windows kernel).