Change Notification States for one user in host.vars.notification.mattermost.users

Hi All,
I have this general valid notification config for mattermost messages:

template Notification "mattermost-host-notification" {
  command = "mattermost_host"
  states = [ Up, Down ]
  types = [ Problem, Acknowledgement, Recovery, Custom, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
  period = "24x7"
  interval = 0
}

template Notification "mattermost-service-notification" {
  command = "mattermost_service"
  states = [ OK, Warning, Critical, Unknown ]
  types = [ Problem, Acknowledgement, Recovery, Custom, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
  period = "24x7"
  interval = 0
}
apply Notification "mattermost" to Host {
  import "mattermost-host-notification"
  users = host.vars.notification.mattermost.users
  assign where host.vars.notification.mattermost
}

apply Notification "mattermost" to Service {
  import "mattermost-service-notification"
  users = host.vars.notification.mattermost.users
  if (service.vars.notification.mattermost.users) {
    users += service.vars.notification.mattermost.users
  }
  assign where host.vars.notification.mattermost
}

object Host "x" {
  ....
  vars.notification.mattermost.users += [ "user1", "user2" ]
  ....
}

What I am trying right now, is to change the service notification types for user2 to only
types = [ Custom, DowntimeStart, DowntimeEnd, DowntimeRemoved ]

I tried an if in the service notification like that:

apply Notification "mattermost" to Service {
  import "mattermost-service-notification"
  users = host.vars.notification.mattermost.users
  if (service.vars.notification.mattermost.users) {
    users += service.vars.notification.mattermost.users
  }
  if (host.vars.notification.mattermost.users == "user2") {
    states = [ OK, Warning, Critical, Unknown ]
    types = [ Custom, DowntimeStart, DowntimeEnd, DowntimeRemoved ]
  }
  assign where host.vars.notification.mattermost
}

But it doesn’t work, Problems are still sent for user2. Also in the icinga2 object list I get:

  * types = [ "Problem", "Acknowledgement", "Recovery", "Custom", "DowntimeStart", "DowntimeEnd", "DowntimeRemoved" ]
  * users = [ "user1", "user2" ]

Can somebody give me a hand to solve this?

Cheers,
Marcus

That will never match, since users is an array and you’re comparing it against a string value. If you want to check whether a string element exists in an array, use the in operator.

"user2" in ...users

Cheers,
Michael

That’s it! Thanks Michi!