Possible apply rule issue for hostgroups (OR followed by AND)

Afternoon,

I’m using Director version 1.6.2 and am attempting to create an apply rule for a hostgroup. The basic premise being if the device has an IP matching any of these patterns, but is not in the switch group, add to the servers group.

Screenshot:
HostGroupApply

Generates this code:

object HostGroup "Servers" {
    display_name = "Servers"
    assign where match("10.20.32.*", host.address) || match("10.20.33.*", host.address) || !("Switches" in host.groups)
}

My switch is still pulled in to the group as it has an IP of 10.20.32.5, despite being in the switches host group.

I think the problem here is the generated code says or (||) when it should say and for the final part:

|| !("Switches" in host.groups)

I’m assuming this should actually be:

&& !("Switches" in host.groups)

If others are able to reproduce this and believe it’s a bug, I’m happy to raise the relevant github issue for it.

Advice appreciated.

This indeed looks odd, have you tried reversing the order , i.e
!(“Switches” in host.groups) && (“10.20.32.", host.address) || ("10.20.33.”, host.address)

@aflatto it doesn’t look like you can start with a not, or rather as soon as you say not you immediately get the option to choose and / or. Instead I’ve moved the not to be part of the condition as below.

I’ve tried this configuration:
ServersReversed

which renders:

object HostGroup "Servers reversed" {
    display_name = "Servers reversed"
    assign where !("Switches" in host.groups) && (match("10.20.32.*", host.address) || match("10.20.33.*", host.address))
}

The apply rule still shows the switch as a member, so perhaps Director isn’t evaluating after the direct assignment of “Server-Switch” to the “Switches” hostgroup?

If I explicitly state “hostname is not Server-Switch” then the switch is correctly removed:
ReversedExcludingName

giving:

object HostGroup "Servers reversed" {
    display_name = "Servers reversed"
    assign where host.name != "Server-Switch" && (match("10.20.32.*", host.address) || match("10.20.33.*", host.address))
}

This certainly feels like a bug as I’d expect to be able to do that either way round. I’d also expect directly assigned groups to be usable in apply rules.

Am I doing something wrong?

I found a bug for exactly you problem: https://github.com/Icinga/icingaweb2-module-director/issues/686
But it was fixed in v1.4.0

Just to be sure:

  • Is your host group definitely named exactly “Switches” (case-sensitivity matters!) ? You should get a drop down list when typing in the name and then can choose the correct group.
  • Is your host “Server-Switch” inside that host group?

You could try working with host.groups = Switches and put a NOT infront:
image

While typing I am seeing that you are assigning a host group. I’m not sure if you can assign host groups “based” on host groups :man_shrugging:

Maybe just open an issue on github for this?

1 Like

have you tried adding the switches as an ignore after the assign where?

assign where match(“10.20.32.", host.address) || match("10.20.33.”, host.address)
ignore where host.name == “Server-Switch”

1 Like

Hi @log1c, that bug looks similar, but I don’t think it’s quite a match for this. Hard to tell as there’s no parenthesis to group clauses.

The host group is definitely names “Switches” and is indeed picked out of the drop down. The “Server-Switch” is definitely in that group - assigned by apply rule. I’ve just changed that to be a direct mapping on the “Server-Switch” object in case that’s a better route, although that didn’t resolve the problem.

Your suggestion of going and not or seems to have done the trick, giving:

object HostGroup "ServersMarch8th" {
    display_name = "Testing from forum"
    assign where !("Switches" in host.groups) && (match("10.20.32.*", host.address) || match("10.20.33.*", host.address))
}

Interestingly, going or and not does not have the desired effect:

object HostGroup "Servers" {
    display_name = "Servers"
    assign where match("10.200.32.*", host.address) || match("10.200.33.*", host.address) || !("Switches" in host.groups)
}

Question is, do I raise this as a bug (as semantically I’d have expected my earlier attempt to work) or was I just doing it wrong? I’m happy with either answer and don’t want to raise an issue on GitHub, wasting someone’s time, if I’ve just misunderstood.

Sorry @petew, I’m not sure how I’d do that in Director? I can’t see an ignore element in the UI.