Director match to hostgroup

director
notifications
#1

Hi,

How to assign a match value in hostgroups using director.

Ex: When i create a notification rule and assign it to match condition like

assign where match("unix", host.groups).

Any insight on how to achieve this via director will be great.

Thanks,

(Thomas Widhalm) #2

How about a workaround? Assign the hostgroup via a template and use this template for adding other things like notifications.

I’d say, this is more the “Director-way” of doing this.

1 Like
(Michael Friedrich) #3

There’s no match needed with just a string. You’d better rephrase this into

"unix" in host.groups

and this is what works with the contains operator AFAIK.

1 Like
#4

Hello @dnsmichi:

Thanks Much.

But i have many unix host groups with sub names. Hence my plan is to set up something like this.

assign where match(“unix*”, host.groups).

Such that all my below host groups will be part of this check.

Hostgroups:
unix-a
unix-b
unix-c

(Michael Friedrich) #5

Hm, I don’t think that the Director supports that specific thing. Maybe there’s a feature request on GH already.

In the meantime try as @widhalmt suggested.

1 Like
(Rafael Voss) #6

I am using custom vars for it and use them in the director:

object HostGroup "veeam-servers" {
    display_name = "Veeam Servers"
    assign where "veeam" in host.vars.services || "Veeam" in host.vars.services
}

Or with string instead of array:

object HostGroup "unix" {
    display_name = "Unix"
    assign where match("*unix*", host.vars.os || match("debian*", host.vars.os )
}

Than you could just add vars.os = “unix” to your unix host template and it will work.

image

image

I never tried host.groups as @dnsmichi mentioned, but it should work the same way as the Veeam example…

2 Likes
#7

Hello
the problem is the implementation of Director. The mode parameter “matchany” of the function match is missing for this use case. Default is “matchall”.
I know that the Director at other place add this parameter, if the pattern has wildcards and and the text is an array.
For this usecase the function call should be: assign where match(“unix*”, host.groups, matchany).

#8

Can the template be assigned to wildcard of hostgroup? for example can i assign the template to unix* when i have three hostgroups named unix-a, unix-b, unix-c?

(Thomas Widhalm) #9

You have to assign the template in the hos object, so you can’t use wildcards. That’s the import option that’s part of the host definition.