Hostgroup by hostname convention

Hello all,

Sorry for the extra spaces - but needed to get around discourse calling these ‘links’.

If I had a bunch of hosts named something like:

host01 . example . com
host02 . example . com
host03 . example . com

etc…

How would I define a hostgroup to include all current and future hosts following this convention… ie a hostgroup for all ‘host[00-999].example.com’ hosts

Note we also have:
host01-ipmi . example . com
host02-ipmi . example . com
host03-ipmi . example . com
etc

We do not want to include these (at least in this group).

Thanks!

Hi,

you could create a regex match in your apply rule:

object HostGroup "hostgroup_name" {
    display_name = "display name"
    
    assign where regex("^host\\d\\d\\.", host.name)
}

assing where hostname starts with host and match two times any digit + a dot (not a regex pro through :sweat_smile:).

Icinga 2 (version: r2.11.2-1)
Type $help to view available commands.
<1> => host.name = "host01.example.com"
null
<2> => regex("^host\\d\\d\\.", host.name)
true
<3> => host.name = "host01-ipmi.example.com"
null
<4> => regex("^host\\d\\d\\.", host.name)
false

Greetz

1 Like