Icinga 2 在指定时间段之外发送通知

Icinga 2 在指定时间段之外发送通知

我尝试在不同的时间段发送不同的通知,基本上我想在工作时间发送所有通知,但只在下班时间发送标记为紧急的主机的通知。

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 只是一个联系人,电子邮件设置为[电子邮件保护],时间段定义如下

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"
  }
}

然而,即使在指定的工作时间之外,我仍然会通过短信收到所有通知。

答案1

应用规则是自行评估的。如果您的分配/忽略 where 表达式匹配(例如“assign where host.vars.notification.mail”可能匹配所有主机),它们将生成一个通知对象。通过“对象列表”或 rest api 端点 /v1/objects/notifications 验证。第二个应用规则仅匹配您设置的自定义属性,并添加一个额外的通知对象。所以你评论的解决方案完全没问题。

顺便说一句,您可以省略“== true”比较。Icinga 2 会自动为布尔属性假定这一点。

答案2

我发现这个解决方案对我有用:

apply Notification "mike-on" to Host {
  import "mail-host-notification"

  users = [ "sms" ]

  period = "mikehours"

  assign where host.vars.notification.mail && !host.vars.emergency
}

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

我仍然很想知道为什么我原来的解决方案失败了,但无论如何这是一个更好的方法。

相关内容