Language/Operators - Assign Rule


First of all, thats my first post so pardon if i’m not at the rigth category or there are missing informations…

My environment:

  • Version used (icinga2 --version)
    version: 2.13.2-1
  • Operating System and version
    openSUSE Leap 15.3
  • Enabled features (icinga2 feature list)
    Enabled features: api checker command ido-pgsql influxdb2 mainlog notification
  • Icinga Web 2 version and modules (System - About)
    Icinga Web 2 Version 2.9.4
    Git commit d208d1ccfef86606984739e6357138c459146134
    PHP Version 7.4.6
    Git commit date 2021-11-10
  • Config validation (icinga2 daemon -C)
    [2021-12-28 17:07:07 -0300] information/cli: Finished validating the configuration file(s).

I have a TimePeriod being imported in a Notification, the notification was done this way:

# Custom notification because of backup and disk health check routine
apply Notification "dummy-mail-service-sd-dummy-client-backup-nas" to Service {
  import "mail-service-notification"

  states = [ Critical ]
  types = [ Problem ]

  users = [ "dummy.service.desk" ]

  period = "dummy-nas-timeperiod"

  assign where (host.vars.notification.mail && == "nas-01.local.domain" && ( == "linux-snmp-cpu" || == "linux-snmp-load"))

We end up changing the assign rule for better ‘visualization’ and to simplify the way we ‘read’ the rule itself… the new rule is:

assign where (host.vars.notification.mail && == "nas-01.local.domain" && in [ "linux-snmp-cpu", "linux-snmp-load" ])

The problems is, the new rule won’t work and i was’nt able the figure out way… is there any mistake or any other thing i’m not seing here?


Hello :slight_smile:

Did you get this out of the Icinga Director?
I’m using the Director as well, but never have used the in operator in the assign statements, just the contains operator which translates to what you can find about in inside the icinga2 docs (confusing, eh?):
According to the docs ( Language Reference - Icinga 2) in is for checking if an element is contained in an array
“foo” in [ “foo”, “bar” ] => (true)
So I would say it has to be the other way round to fit to the syntax.
But I think then the problem is that isn’t an array, and thus I’m not sure it works that way.

If you can pin it to host or service templates it works with in:

assign where host.vars.os_family == "linux" && "linux-by_ssh-host-template" in host.templates && ! host.vars.appliance

Not sure what to idea/logic behind the in of the Director is.

Hi @log1c

Did you get this out of the Icinga Director?
Nops, in this scenario every config is done directly in cli

I’m also confused about how the in operator works, did a test with icinga2 console (manually seting names, vars, values, etc) and the result was true (as expected by assign rule if i’m not mistaken) but in the end when used in assign rule the result was the same…

We end up replacing the in operator by regex, like this:

assign where (host.vars.notification.mail && == "nas-01.local.domain" && regex("(linux-snmp-cpu|linux-snmp-load)")

Thanks guys!

1 Like