icinga2添加自定义通知插件

添加模板
/etc/icinga2/conf.d/templates.conf

template Notification "wechat-host-notification" {
command = "wechat-host-notification"
states = [ Up, Down ]
types = [ Problem, Recovery ]
period = "24x7"
}
template Notification "wechat-service-notification" {
command = "wechat-service-notification"
states = [ OK, Warning, Critical, Unknown ]
types = [ Problem, Recovery ]
period = "24x7"
}

添加command
/etc/icinga2/conf.d/commands.conf

object NotificationCommand "wechat-host-notification" {
import "plugin-notification-command"
command = [ SysconfDir + "/icinga2/scripts/wechat-host-notification.sh" ]
env = {
NOTIFICATIONTYPE = "$notification.type$"
HOSTALIAS = "$host.display_name$"
HOSTADDRESS = "$address$"
HOSTSTATE = "$host.state$"
LONGDATETIME = "$icinga.long_date_time$"
SHORTDATETIME = "$icinga.short_date_time$"
TIME = "$icinga.time$"
HOSTOUTPUT = "$host.output$"
NOTIFICATIONAUTHORNAME = "$notification.author$"
NOTIFICATIONCOMMENT = "$notification.comment$"
HOSTDISPLAYNAME = "$host.display_name$"
USEREMAIL = "$user.email$"
}
}
object NotificationCommand "wechat-service-notification" {
import "plugin-notification-command"
command = [ SysconfDir + "/icinga2/scripts/wechat-service-notification.sh" ]
env = {
NOTIFICATIONTYPE = "$notification.type$"
SERVICEDESC = "$service.name$"
HOSTALIAS = "$host.display_name$"
HOSTADDRESS = "$address$"
SERVICESTATE = "$service.state$"
LONGDATETIME = "$icinga.long_date_time$"
SHORTDATETIME = "$icinga.short_date_time$"
TIME = "$icinga.time$"
SERVICEOUTPUT = "$service.output$"
NOTIFICATIONAUTHORNAME = "$notification.author$"
NOTIFICATIONCOMMENT = "$notification.comment$"
HOSTDISPLAYNAME = "$host.display_name$"
SERVICEDISPLAYNAME = "$service.display_name$"
USEREMAIL = "$user.email$"
}
}

注册通知到主机和服务
/etc/icinga2/conf.d/notifications.conf

apply Notification "wechat-icingaadmin" to Host {
import "wechat-host-notification"
user_groups = host.vars.notification.mail.groups
assign where host.vars.notification.mail
interval = 0
}
apply Notification "wechat-icingaadmin" to Service {
import "wechat-service-notification"
user_groups = host.vars.notification.mail.groups
assign where host.vars.notification.mail
interval = 0
}

路径/etc/icinga2/scripts

# cat wechat-host-notification.sh

#!/bin/sh
template=\`cat <<TEMPLATE
$SHORTDATETIME|$HOSTALIAS|$HOSTADDRESS|$HOSTSTATE|$HOSTOUTPUT
TEMPLATE
\`
/usr/local/bin/send_wechat.py $USEREMAIL "$template"

# cat wechat-service-notification.sh

#!/bin/sh
template=\`cat <<TEMPLATE
$SHORTDATETIME|$HOSTALIAS|$HOSTADDRESS|$SERVICEDESC|$SERVICESTATE|$SERVICEOUTPUT
TEMPLATE
\`
/usr/local/bin/send_wechat.py $USEREMAIL "$template"

检查配置文件
icinga2 daemon -C

重启icinga2

service icinga2 restart

相关资料: http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/migration