summaryrefslogtreecommitdiffstats
path: root/zones.d
diff options
context:
space:
mode:
authorTobias Wiese <tobias@tobiaswiese.com>2020-05-11 20:35:04 +0200
committerTobias Wiese <tobias@tobiaswiese.com>2020-05-11 20:35:04 +0200
commit50be889b75116ae5b36ea9113e79649df16c6986 (patch)
tree2c9304d31cfa916c7add63147878c1be542a6d6e /zones.d
parent4c255bd3feafb976e0030b699807d0bb8d3957a2 (diff)
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 <tobias@tobiaswiese.com>
Diffstat (limited to 'zones.d')
-rw-r--r--zones.d/global-templates/hosts.conf9
l---------zones.d/master/features/notification.conf1
-rw-r--r--zones.d/master/notification-commands.conf201
-rw-r--r--zones.d/master/notifications.conf72
-rw-r--r--zones.d/master/users.conf15
5 files changed, 298 insertions, 0 deletions
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"
+}