From 50be889b75116ae5b36ea9113e79649df16c6986 Mon Sep 17 00:00:00 2001 From: Tobias Wiese Date: Mon, 11 May 2020 20:35:04 +0200 Subject: notifications: Notify via email and telegram Provide notification in case of a state change via email and telegram bot. The telegram bot is especially helpful in cases where a problem with email delivery is to be reportet. Signed-off-by: Tobias Wiese --- zones.d/global-templates/hosts.conf | 9 ++ zones.d/master/features/notification.conf | 1 + zones.d/master/notification-commands.conf | 201 ++++++++++++++++++++++++++++++ zones.d/master/notifications.conf | 72 +++++++++++ zones.d/master/users.conf | 15 +++ 5 files changed, 298 insertions(+) create mode 120000 zones.d/master/features/notification.conf create mode 100644 zones.d/master/notification-commands.conf create mode 100644 zones.d/master/notifications.conf create mode 100644 zones.d/master/users.conf (limited to 'zones.d') diff --git a/zones.d/global-templates/hosts.conf b/zones.d/global-templates/hosts.conf index e301dcf..ccc8007 100644 --- a/zones.d/global-templates/hosts.conf +++ b/zones.d/global-templates/hosts.conf @@ -1,3 +1,12 @@ template Host "generic-host" { check_command = "hostalive" + + /* Notifications */ + vars.notification["mail"] = { + groups = [ "hostmaster" ] + } + + vars.notification["telegram"] = { + groups = [ "hostmaster" ] + } } diff --git a/zones.d/master/features/notification.conf b/zones.d/master/features/notification.conf new file mode 120000 index 0000000..b143504 --- /dev/null +++ b/zones.d/master/features/notification.conf @@ -0,0 +1 @@ +../../../features-available/notification.conf \ No newline at end of file diff --git a/zones.d/master/notification-commands.conf b/zones.d/master/notification-commands.conf new file mode 100644 index 0000000..57b15fe --- /dev/null +++ b/zones.d/master/notification-commands.conf @@ -0,0 +1,201 @@ +template NotificationCommand "generic-notification" { + vars += { + notification_address = "$address$" + notification_address6 = "$address6$" + notification_author = "$notification.author$" + notification_comment = "$notification.comment$" + notification_date = "$icinga.long_date_time$" + notification_icingaweb2url = IcingaWebUrl + notification_hostdisplayname = "$host.display_name$" + notification_hostname = "$host.name$" + notification_type = "$notification.type$" + } +} + +template NotificationCommand "generic-host-notification" { + import "generic-notification" + vars += { + notification_hostoutput = "$host.output$" + notification_hoststate = "$host.state$" + } +} + +template NotificationCommand "generic-service-notification" { + import "generic-notification" + vars += { + notification_servicedisplayname = "$service.display_name$" + notification_servicename = "$service.name$" + notification_serviceoutput = "$service.output$" + notification_servicestate = "$service.state$" + } +} + +object NotificationCommand "mail-host-notification" { + import "generic-host-notification" + + command = [ ConfigDir + "/scripts/mail-host-notification.sh" ] + + arguments += { + "-4" = "$notification_address$" + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-f" = { + value = "$notification_from$" + description = "Set from address." + } + "-i" = "$notification_icingaweb2url$" + "-l" = { + required = true + value = "$notification_hostname$" + } + "-n" = { + required = true + value = "$notification_hostdisplayname$" + } + "-o" = { + required = true + value = "$notification_hostoutput$" + } + "-r" = { + required = true + value = "$notification_useremail$" + } + "-s" = { + required = true + value = "$notification_hoststate$" + } + "-t" = { + required = true + value = "$notification_type$" + } + "-v" = "$notification_logtosyslog$" + } + + vars += { + notification_useremail = "$user.email$" + } +} + +object NotificationCommand "mail-service-notification" { + import "generic-service-notification" + + command = [ ConfigDir + "/scripts/mail-service-notification.sh" ] + + arguments += { + "-4" = "$notification_address$" + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-e" = { + required = true + value = "$notification_servicename$" + } + "-f" = { + value = "$notification_from$" + description = "Set from address." + } + "-i" = "$notification_icingaweb2url$" + "-l" = { + required = true + value = "$notification_hostname$" + } + "-n" = { + required = true + value = "$notification_hostdisplayname$" + } + "-o" = { + required = true + value = "$notification_serviceoutput$" + } + "-r" = { + required = true + value = "$notification_useremail$" + } + "-s" = { + required = true + value = "$notification_servicestate$" + } + "-t" = { + required = true + value = "$notification_type$" + } + "-u" = { + required = true + value = "$notification_servicedisplayname$" + } + "-v" = "$notification_logtosyslog$" + } + + vars += { + notification_useremail = "$user.email$" + } +} + +object NotificationCommand "telegram-host-notification" { + import "generic-host-notification" + + command = [ ConfigDir + "/scripts/telegram-host-notification.sh" ] + + env = { + ADDRESS = "$notification_address$" + ADDRESS6 = "$notification_address6$" + AUTHOR = "$notification_author$" + COMMENT = "$notification_comment$" + DATE = "$notification_date$" + ICINGAWEB2URL = "$notification_icingaweb2url$" + HOSTDISPLAYNAME = "$notification_hostdisplayname$" + HOSTNAME = "$notification_hostname$" + TYPE = "$notification_type$" + + HOSTOUTPUT = "$notification_hostoutput$" + HOSTSTATE = "$notification_hoststate$" + + USERCHATID = "$notification_userchatid$" + TOKEN = "$notification_token$" + } + + vars += { + notification_userchatid = "$user.vars.telegram$" + notification_token = TelegramBotToken + } +} + +object NotificationCommand "telegram-service-notification" { + import "generic-service-notification" + + command = [ ConfigDir + "/scripts/telegram-service-notification.sh" ] + + env = { + ADDRESS = "$notification_address$" + ADDRESS6 = "$notification_address6$" + AUTHOR = "$notification_author$" + COMMENT = "$notification_comment$" + DATE = "$notification_date$" + ICINGAWEB2URL = "$notification_icingaweb2url$" + HOSTDISPLAYNAME = "$notification_hostdisplayname$" + HOSTNAME = "$notification_hostname$" + TYPE = "$notification_type$" + + SERVICEDISPLAYNAME = "$notification_servicedisplayname$" + SERVICENAME = "$notification_servicename$" + SERVICEOUTPUT = "$notification_serviceoutput$" + SERVICESTATE = "$notification_servicestate$" + + USERCHATID = "$notification_userchatid$" + TOKEN = "$notification_token$" + } + + vars += { + notification_userchatid = "$user.vars.telegram$" + notification_token = TelegramBotToken + } +} diff --git a/zones.d/master/notifications.conf b/zones.d/master/notifications.conf new file mode 100644 index 0000000..b980851 --- /dev/null +++ b/zones.d/master/notifications.conf @@ -0,0 +1,72 @@ +template Notification "generic-notification" { + types = [ + Problem, + Acknowledgement, + Recovery, + Custom, + FlappingStart, + FlappingEnd, + ] +} + +template Notification "generic-host-notification" { + import "generic-notification" + states = [ Up, Down ] +} + +template Notification "generic-service-notification" { + import "generic-notification" + states = [ OK, Warning, Critical, Unknown ] +} + +apply Notification "mail" to Host { + import "generic-host-notification" + + command = "mail-host-notification" + + user_groups = host.vars.notification.mail.groups + users = host.vars.notification.mail.users + + interval = 2h + + assign where host.vars.notification.mail +} + +apply Notification "mail" to Service { + import "generic-service-notification" + + command = "mail-service-notification" + + user_groups = host.vars.notification.mail.groups + users = host.vars.notification.mail.users + + interval = 2h + + assign where host.vars.notification.mail +} + +apply Notification "telegram" to Host { + import "generic-host-notification" + + command = "telegram-host-notification" + + user_groups = host.vars.notification.telegram.groups + users = host.vars.notification.telegram.users + + interval = 2h + + assign where host.vars.notification.telegram +} + +apply Notification "telegram" to Service { + import "generic-service-notification" + + command = "telegram-service-notification" + + user_groups = host.vars.notification.telegram.groups + users = host.vars.notification.telegram.users + + interval = 2h + + assign where host.vars.notification.telegram +} diff --git a/zones.d/master/users.conf b/zones.d/master/users.conf new file mode 100644 index 0000000..03072d3 --- /dev/null +++ b/zones.d/master/users.conf @@ -0,0 +1,15 @@ +template User "generic-user" { } + +object User "hostmaster" { + import "generic-user" + + display_name = "tobiaswiese.net Hostmaster" + groups = [ "hostmaster" ] + + email = "hostmaster@tobiaswiese.net" + vars.telegram = -1001430477767 +} + +object UserGroup "hostmaster" { + display_name = "tobiaswiese.net Hostmaster Group" +} -- cgit v1.2.3