我已将 icinga2 设置为以不同的时间间隔监视一些服务,因此可能每 10 秒检查一次服务。如果出现严重错误,我会收到通知,但如果错误仍然存在,我将每 10 秒收到一次通知,或者直到我确认为止。我只想在每次状态更改时收到一次。然后可能会在指定时间后再次出现,但这并不重要。
这是我的配置:
这或多或少是标准的 template.conf,但我添加了“interval=0s”,因为我读到它应该防止通知被多次发送。
template Notification "mail-service-notification" {
command = "mail-service-notification"
interval = 0s
states = [ OK, Critical ]
types = [ Problem, Acknowledgement, Recovery, Custom,
FlappingStart, FlappingEnd,
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
vars += {
notification_logtosyslog = false
}
period = "24x7"
}
这是包含模板的 notification.conf 部分:
object NotificationCommand "telegram-service-notification" {
import "plugin-notification-command"
command = [ SysconfDir + "/icinga2/scripts/telegram-service-notification.sh" ]
env = {
NOTIFICATIONTYPE = "$notification.type$"
SERVICEDESC = "$service.name$"
HOSTNAME = "$host.name$"
HOSTALIAS = "$host.display_name$"
HOSTADDRESS = "$address$"
SERVICESTATE = "$service.state$"
LONGDATETIME = "$icinga.long_date_time$"
SERVICEOUTPUT = "$service.output$"
NOTIFICATIONAUTHORNAME = "$notification.author$"
NOTIFICATIONCOMMENT = "$notification.comment$"
HOSTDISPLAYNAME = "$host.display_name$"
SERVICEDISPLAYNAME = "$service.display_name$"
TELEGRAM_BOT_TOKEN = TelegramBotToken
TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$"
}
}
apply Notification "telegram-icingaadmin" to Service {
import "mail-service-notification"
command = "telegram-service-notification"
user_groups = [ "icingaadmins" ]
assign where host.name
}
最佳答案
我想你打错了。
如果您设置 interval = 0
(而不是“interval = 0s”),它应该可以工作
更改后,您必须重新启动 icinga 服务。
关于Icinga2 仅在状态更改时通知一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50871100/