From 12ce8d8f6ef79fae74dacbab3013d3b5048fe28c Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 22 Nov 2020 13:28:14 +0100 Subject: [PATCH] bundles/icinga2: add automatic downtime for upgrade-and-reboot --- bundles/icinga2/files/icinga2/downtimes.conf | 18 ++++++++++++++ bundles/icinga2/items.py | 25 ++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 bundles/icinga2/files/icinga2/downtimes.conf diff --git a/bundles/icinga2/files/icinga2/downtimes.conf b/bundles/icinga2/files/icinga2/downtimes.conf new file mode 100644 index 0000000..cb00e32 --- /dev/null +++ b/bundles/icinga2/files/icinga2/downtimes.conf @@ -0,0 +1,18 @@ +% for monitored_node in sorted(monitored_nodes): +% if not monitored_node.dummy: +object ScheduledDowntime "unattended_upgrades" { + host_name = "${monitored_node.name}" + + author = "upgrade-and-reboot" + comment = "Downtime for upgrade-and-reboot" + + fixed = true + + ranges = { + "${days[monitored_node.metadata.get('apt', {}).get('unattended_upgrades', {}).get('day', 5)]}" = "01:${monitored_node.magic_number%30}-01:${(monitored_node.magic_number%30)+30}" + } + + child_options = "DowntimeTriggeredChildren" +} +% endif +% endfor diff --git a/bundles/icinga2/items.py b/bundles/icinga2/items.py index 0836885..0aead44 100644 --- a/bundles/icinga2/items.py +++ b/bundles/icinga2/items.py @@ -17,6 +17,17 @@ SLA_INFO = { 'never': 'never', } +DAYS_TO_STRING = [ + 'sunday', + 'monday', + 'tuesday', + 'wednesday', + 'thursday', + 'friday', + 'saturday', + 'sunday', +] + directories = { '/etc/icingaweb2': { 'group': 'icingaweb2', @@ -316,3 +327,17 @@ files['/etc/icinga2/conf.d/groups.conf'] = { 'svc_systemd:icinga2:restart', }, } +files['/etc/icinga2/conf.d/downtimes.conf'] = { + 'source': 'icinga2/downtimes.conf', + 'content_type': 'mako', + 'context': { + 'monitored_nodes': monitored_nodes, + 'days': DAYS_TO_STRING, + }, + 'needs': { + 'pkg_apt:icinga2', + }, + 'triggers': { + 'svc_systemd:icinga2:restart', + }, +}