Browse Source

icinga2: use region for notifications

Dominique Flemming-Schmidt 3 years ago
parent
commit
d05bd62787
2 changed files with 126 additions and 0 deletions
  1. 9 0
      icinga2/init.sls
  2. 117 0
      icinga2/notifications.conf.tmpl

+ 9 - 0
icinga2/init.sls

@@ -163,6 +163,15 @@ ffho-plugins:
     - watch_in:
       - service: icinga2
 
+/etc/icinga2/ffho-conf.d/notifications.conf:
+  file.managed:
+    - source: salt://icinga2/notifications.conf.tmpl
+    - template: jinja
+    - require:
+      - pkg: icinga2
+    - watch_in:
+      - service: icinga2
+
 # Install command definitions
 /etc/icinga2/ffho-conf.d/services:
   file.recurse:

+ 117 - 0
icinga2/notifications.conf.tmpl

@@ -0,0 +1,117 @@
+################################################################################
+#                              Notification commands                           #
+################################################################################
+
+object NotificationCommand "telegram-notification-command" {
+        import "plugin-notification-command"
+
+	command = [ SysconfDir + "/icinga2/scripts/telegram-notification.py" ]
+	env = {
+		TELEGRAM_BOT_TOKEN = "{{ salt['pillar.get']('monitoring:private:telegram_bot_token') }}"
+		TELEGRAM_CHAT_ID = "$user.vars.telegram_chat_id$"
+		NOTIFICATION_TYPE = "$notification.type$"
+		MESSAGE = "$telegram_message$"
+		ACKNOWLEDGE_CALLBACK = "$acknowledge_callback$"
+	}
+}
+
+object NotificationCommand "telegram-host-notification" {
+	import "telegram-notification-command"
+
+	vars.telegram_message = "$notification.type$ - $host.display_name$ is $host.state$"
+	vars.acknowledge_callback = "HOST!$host.name$"
+}
+
+object NotificationCommand "telegram-service-notification" {
+	import "telegram-notification-command"
+
+	vars.telegram_message = "$notification.type$ $service.display_name$ auf $host.display_name$ $service.output$"
+	vars.acknowledge_callback = "SERVICE!$host.name$!$service.name$"
+}
+
+
+################################################################################
+#                           Notification Templates                             #
+################################################################################
+
+template Notification "telegram-host-notification" {
+	command = "telegram-host-notification"
+	states = [ Up, Down ]
+	types = [ Problem, Acknowledgement, Recovery, Custom,
+	          FlappingStart, FlappingEnd,
+	]
+
+	period = "24x7"
+	interval = 0
+}
+
+template Notification "telegram-service-notification" {
+	command = "telegram-service-notification"
+
+	states = [ OK, Warning, Critical, Unknown ]
+	types = [ Problem, Acknowledgement, Recovery, Custom,
+	          FlappingStart, FlappingEnd,
+	]
+
+	period = "24x7"
+	interval = 0
+}
+				  
+
+
+################################################################################
+#                                  Notifications                               #
+################################################################################
+
+apply Notification "notify_host_ffho_ops_by_telegram" to Host {
+	import "telegram-host-notification"
+
+	users = [ "ffho-ops" ]
+	period = "24x7"
+	
+	times.begin = 2m
+
+	assign where host.address
+}
+
+apply Notification "notify_service_ffho_ops_telegram" to Service {
+	import "telegram-service-notification"
+
+	users = [ "ffho-ops" ]
+	period = "24x7"
+
+	times.begin = 2m
+
+	assign where host.address
+	ignore where service.name == "apt-Updates"
+	ignore where service.name == "libs"
+	ignore where service.name == "running_kernel"
+	ignore where service.name == "salt"
+}
+
+
+apply Notification "notify_host_ffho_dek_by_telegram" to Host {
+	import "telegram-host-notification"
+
+	users = [ "ffho-dek" ]
+	period = "24x7"
+	
+	times.begin = 2m
+
+	assign where host.vars.location.region.code == "ffho_dek"
+}
+
+apply Notification "notify_service_ffho_dek_telegram" to Service {
+	import "telegram-service-notification"
+
+	users = [ "ffho-dek" ]
+	period = "24x7"
+
+	times.begin = 2m
+
+	assign where host.vars.location.region.code == "ffho_dek"
+	ignore where service.name == "apt-Updates"
+	ignore where service.name == "libs"
+	ignore where service.name == "running_kernel"
+	ignore where service.name == "salt"
+}