From 65ba43525fd4bf611cd9fa82faeb3f585e73af17 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sat, 5 Mar 2022 08:29:10 +0100 Subject: [PATCH] bundles/icinga2: introduce new notification period 'daytime' --- .../icinga2/files/icinga2/hosts_template.conf | 3 +-- .../icinga2/files/icinga2/notifications.conf | 6 ++++++ .../icinga2/files/icinga2/timeperiods.conf | 19 ++++++++++++------- bundles/icinga2/items.py | 6 ------ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bundles/icinga2/files/icinga2/hosts_template.conf b/bundles/icinga2/files/icinga2/hosts_template.conf index 645fa27..3d3cae2 100644 --- a/bundles/icinga2/files/icinga2/hosts_template.conf +++ b/bundles/icinga2/files/icinga2/hosts_template.conf @@ -11,8 +11,7 @@ object Host "${rnode.name}" { # used for status page vars.pretty_name = "${rnode.metadata.get('icinga_options/pretty_name', rnode.name)}" - vars.period = "${sla_info[rnode.metadata.get('sla', '24x7')]}" - vars.sla = "${rnode.metadata.get('sla', '24x7')}" + vars.period = "${rnode.metadata.get('icinga_options/period', '24x7')}" vars.notification.sms = ${str(rnode.metadata.get('icinga_options/vars.notification.sms', True)).lower()} vars.notification.mail = true diff --git a/bundles/icinga2/files/icinga2/notifications.conf b/bundles/icinga2/files/icinga2/notifications.conf index 0183a45..71e1060 100644 --- a/bundles/icinga2/files/icinga2/notifications.conf +++ b/bundles/icinga2/files/icinga2/notifications.conf @@ -6,6 +6,8 @@ apply Notification "notify_host-notification" to Host { begin = 0m } + period = host.vars.period + assign where host.vars.notification.sms == true } @@ -17,6 +19,8 @@ apply Notification "notify_service-notification" to Service { begin = 0m } + period = host.vars.period + assign where service.vars.notification.sms == true ignore where host.vars.notification.sms == false } @@ -25,6 +29,8 @@ apply Notification "notify_service-notification-mail" to Service { import "service-notification" interval = 0 + period = host.vars.period + assign where service.vars.notification.mail == true ignore where service.vars.notification.sms == true ignore where host.vars.notification.mail == false diff --git a/bundles/icinga2/files/icinga2/timeperiods.conf b/bundles/icinga2/files/icinga2/timeperiods.conf index eb1953d..36ac585 100644 --- a/bundles/icinga2/files/icinga2/timeperiods.conf +++ b/bundles/icinga2/files/icinga2/timeperiods.conf @@ -13,16 +13,21 @@ object TimePeriod "24x7" { } } -object TimePeriod "weekdays_9to6" { +object TimePeriod "daytime" { import "legacy-timeperiod" - display_name = "9to6 (UTC)" + # 5AM UTC to 8PM UTC + # 6AM MEZ to 9PM MEZ + # 7AM MESZ to 10PM MESZ + display_name = "5AM to 8PM (UTC)" ranges = { - "monday" = "09:00-18:00" - "tuesday" = "09:00-18:00" - "wednesday" = "09:00-18:00" - "thursday" = "09:00-18:00" - "friday" = "09:00-18:00" + "monday" = "06:00-20:00" + "tuesday" = "06:00-20:00" + "wednesday" = "06:00-20:00" + "thursday" = "06:00-20:00" + "friday" = "06:00-20:00" + "saturday" = "07:00-20:00" + "sunday" = "07:00-20:00" } } diff --git a/bundles/icinga2/items.py b/bundles/icinga2/items.py index 3ffd860..be47da3 100644 --- a/bundles/icinga2/items.py +++ b/bundles/icinga2/items.py @@ -11,11 +11,6 @@ ENABLED_FEATURES = { 'notification', } -SLA_INFO = { - '24x7': '24x7', - 'never': 'never', -} - DAYS_TO_STRING = [ 'sunday', 'monday', @@ -340,7 +335,6 @@ for rnode in repo.nodes: 'content_type': 'mako', 'context': { 'rnode': rnode, - 'sla_info': SLA_INFO, }, 'owner': 'nagios', 'group': 'nagios',