icingaweb2-module-director icon indicating copy to clipboard operation
icingaweb2-module-director copied to clipboard

Deployment failure when using the contains operator with string properties in apply rules

Open lippserd opened this issue 8 years ago • 8 comments

When creating a service apply rule using the contains operator with host.name for example, the generated configuration is invalid because the Director renders this as "filter" in host.name which is not yet supported: Icinga/icinga2#5018.

It would be optimal, if the Director offers the appropriate operators based on the type of the property. But I think it would be sufficient for the moment to document that the contains operator is only valid for array properties.

@Thomas-Gelf What are your thoughts about this?

lippserd avatar Feb 21 '17 09:02 lippserd

Added my comments over there. This is at least a documentation/GUI issue, "contains" should not be shown when dealing with non-array values. Just, this is sometimes not as clear as one might think - as the same variable might be filled with either strings or arrays depending on who/where you are.

The correct way to accomplish wild-card matches in the Director is by using the = (equals) operator combined with wild-cards (using the asterisk *). host.name = *filter* renders to where match("*filter*", host.name)*.

However, I fully understand the problem that "contains" might be misleading especially to people new to the Director (read: those who didn't use it before 1.3.0). This should somehow be addressed.

Thomas-Gelf avatar Feb 21 '17 10:02 Thomas-Gelf

+1 This fixed a frustrating issue I was having trying to create Service Groups - just needing to use "=" with wildcards instead of the "contains" filter.

pillbug22 avatar Sep 06 '17 21:09 pillbug22

Hi Tom,

We decided to not support the in operator for strings at the moment. It would be great if you could add a hint somewhere that the contains operator will not work for strings.

Cheers, Eric

lippserd avatar Sep 08 '17 13:09 lippserd

@lippserd: yep, there should be a related issue. Just didn't know where to place the hint :laughing: Good decision to not allow this in Icinga, also IMO it would make no sense.

Thomas-Gelf avatar Sep 08 '17 14:09 Thomas-Gelf

ref/IP/14611

carraroj avatar May 17 '19 07:05 carraroj

Hello, Just to understand, is it wanted in Director implementation "contains" is replaced by "in" ? I mean instead of using the contains method $string_var$.contains($string$).

Slevinox avatar Aug 30 '19 09:08 Slevinox

This is confusing that you have to use = with wildcard. Usually wildcards only work with LIKE.

PS: I guess theres also a director gui issue with IN. if you have selected it you cannot switch back to another operator.

bitboy85 avatar Dec 19 '19 16:12 bitboy85

why does this not work?:

apply Service "EOL Status" {
    import "service_compliance"

    check_command = "warning_end_of_life_info"
    assign where match("*[os]_red_hat_enterprise_linux_8.5_*", host.groups)
    groups = [ "end_of_life" ]
    zone = "backend"

    import DirectorOverrideTemplate
}

it should match to all hosts there are in hostgroup "[os]_red_hat_enterprise_linux_8.5_(Ootpa)" or am I thinking wrong? Hosts are in multiple Hostgroups, is this the reason why it doesnt work?

I cant use the whole group name because if I have '()' in hostgroupname I get a filter error. It is possible to escape '()' somehow?

MAngel666 avatar Sep 08 '22 14:09 MAngel666