icinga2/nagios 分级通知

icinga是nagios的派生版,但又增加了很多改进,icinga2版本配置文件变化较大。
下面是设置分级别通知策略的配置方法。
分级通知主要用于 业务负责人员未收到通知的情况通知全体联系人。

下面的配置解析:
出现问题后立刻通知web组管理员,如果15分钟后问题没有得到处理,接下来的30分钟以每5分钟一次的频率再次通知web组管理员;45分钟后问题仍存在,通知所有管理员。

vim /etc/icinga2/conf.d/notifications.conf

// start of escalation notification level
apply Notification "wechat-2nd-level-web" to Service {
import "wechat-service-notification-template"
user_groups = [ "admins-web" ]
interval = 5m
times = {
begin = 15m
end = 45m
}
assign where service.name == "ping4"
assign where match("nrpe_disk_read_write", service.name)
}
apply Notification "wechat-1st-level-web" to Service {
import "wechat-service-notification-template"
user_groups = [ "icingaadmins" ]
interval = 15m
times = {
begin = 45m
end = 2h
}
assign where service.name == "ping4"
assign where match("nrpe_disk_read_write", service.name)
}
// end of escalation notification level

官方的文档如下

Similar example for advanced notification apply rule filters: If the service attribute notes contains the has gold support 24x7 string AND one of the two condition passes: Either the customer host custom attribute is set to customer-xy OR the host custom attribute always_notify is set to true.

The notification is ignored for services whose host name ends with *internal OR the priority custom attribute is less than 2.

template Notification "cust-xy-notification" {
users = [ "noc-xy", "mgmt-xy" ]
command = "mail-service-notification"
}
apply Notification "notify-cust-xy-mysql" to Service {
import "cust-xy-notification"
assign where match("*has gold support 24x7*", service.notes) && (host.vars.customer == "customer-xy" || host.vars.always_notify == true)
ignore where match("*internal", host.name) || (service.vars.priority < 2 && host.vars.is_clustered == true)
}

If the problem does not get resolved nor acknowledged preventing further notifications the escalation-sms-1st-level user will be escalated 1h after the initial problem was notified, but only for one hour (2h as end key for the times dictionary).

apply Notification "mail" to Service {
import "generic-notification"
command = "mail-notification"
users = [ "icingaadmin" ]
assign where service.name == "ping4"
}
apply Notification "escalation-sms-2nd-level" to Service {
import "generic-notification"
command = "sms-notification"
users = [ "icinga-oncall-2nd-level" ]
times = {
begin = 30m
end = 1h
}
assign where service.name == "ping4"
}
apply Notification "escalation-sms-1st-level" to Service {
import "generic-notification"
command = "sms-notification"
users = [ "icinga-oncall-1st-level" ]
times = {
begin = 1h
end = 2h
}
assign where service.name == "ping4"
}

官方关于notification定义的文档
官方关于notification配置技巧文档