The good thing is, that now you can use apply rules to add hostgroups to hosts based on the attributes of the hosts. You don’t have to define them explicitly anymore. Like in the linked example.
But the best thing about this is that you don’t have to use hostgroups anymore. If you really want them, you can have them, but most things that were done by hostgroups can now be achieved much easier.
You can use apply rules to assign Services to hosts according to the hosts’ attributes. (Custom vars, patterns of names, patterns of addresses etc.)
You can build filters in Icinga Web 2, the API etc. based on these attributes, too.
So there’s really no need for hostgroups anymore. Please don’t try to use them in the “traditional” way - only for a quicker way of filtering your views or in combination with external tools that rely on them.
This obviously work for a single host but I have about 24 servers which I would like to apply this check do and really don’t want to write this out 24 times specifying the individual hosts.
apply Service "App1" {
import "generic-service"
check_command = "http"
vars.sla = "24x7"
vars.http_port = 8080
vars.notification[“mail”] = { groups = [ “icingaadmins” ] }
apply where host.vars.app == "app1"
And on your host objects you add: vars.app = "app1"
Keep in mind that this is only one simple example what you can do. You can use assign where with pattern matching, compare every attribute and combine rules with || and &&.
If you add this and run icinga2 object list you will see Service objects being created for every host where the custom var app is set to app1. Icinga 2 knows the Service objects like you had them in Nagios but you don’t need to define them anymore but can let Icinga 2 do the heavy lifting with apply rules. The best part about this is that you don’t have to bother with Service objects to add or remove if you add or remove hosts. Whenever you restart/reload Icinga 2 the rules get evaluated.
And you can set custom vars like http_port on your host object. So if some hosts use 8080 but some use 80 you can still use a single rule.