Icinga 2 sends notifications outside of specified time period

icingaicinga2monitoring

I'm trying to send different notifications in different time periods, basically I want to send all notifications during work hours, but only notifications for hosts marked emergency during off hours.

apply Notification "mike-on" to Host {
  import "mail-host-notification"
  users = [ "sms" ]
  period = "mikehours"
  assign where host.vars.notification.mail
}

apply Notification "mike-off" to Host {
  import "mail-host-notification"
  users = [ "sms" ]
  period = "nonmikehours"
  assign where host.vars.emergency == true
}

sms is simply a contact with the email set to mynumber@carrier.net, and the time periods are defined as follows

object TimePeriod "mikehours" {
  import "legacy-timeperiod"

  display_name = "Mike's work hours"
  ranges = {
    "monday"    = "06:00-23:00"
    "tuesday"   = "06:00-23:00"
    "wednesday" = "06:00-23:00"
    "thursday"  = "06:00-23:00"
    "friday"    = "06:00-23:00"
    "saturday"  = "07:00-22:00"
    "sunday"    = "07:00-22:00"
  }
}

object TimePeriod "nonmikehours" {
  import "legacy-timeperiod"
  display_name = "Mike's off hours"
  ranges = {
    "monday"    = "00:00-06:00,23:00-24:00"
    "tuesday"   = "00:00-06:00,23:00-24:00"
    "wednesday" = "00:00-06:00,23:00-24:00"
    "thursday"  = "00:00-06:00,23:00-24:00"
    "friday"    = "00:00-06:00,23:00-24:00"
    "saturday"  = "00:00-07:00,22:00-24:00"
    "sunday"    = "00:00-07:00,22:00-24:00"
  }
}

However, I still receive all notifications via sms even outside of the specified work hours.

Best Answer

Apply rules are evaluated on their own. If your assign/ignore where expressions match (as with "assign where host.vars.notification.mail" probably matching all hosts) they will generate a notification object. Verify that by 'object list' or the rest api endpoint /v1/objects/notifications. The second apply rule only matches on your custom attribute being set, and adds an additional notification object. So your comment's solution is perfectly fine.

You can omit the "== true" comparison btw. Icinga 2 assumes that automatically for boolean attributes.

Related Topic