From d428572461aa029c2d3681821695d32c130b2f7f Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sat, 21 Nov 2020 23:04:15 +0100 Subject: [PATCH] bundles/icinga2: add servicegroup for every service which has checks --- bundles/icinga2/files/icinga2/groups.conf | 8 +++++++ .../files/icinga2/services_template.conf | 1 + bundles/icinga2/items.py | 24 +++++++++++-------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/bundles/icinga2/files/icinga2/groups.conf b/bundles/icinga2/files/icinga2/groups.conf index 4c3ce1e..f621295 100644 --- a/bundles/icinga2/files/icinga2/groups.conf +++ b/bundles/icinga2/files/icinga2/groups.conf @@ -5,3 +5,11 @@ object HostGroup "group-${group.name}" { assign where "${group.name}" in host.vars.bw_groups } % endfor + +% for bundle in sorted(bundles): +object ServiceGroup "bundle-${bundle}" { + display_name = "bw bundle ${bundle}" + + assign where service.vars.bundle == "${bundle}" +} +% endfor diff --git a/bundles/icinga2/files/icinga2/services_template.conf b/bundles/icinga2/files/icinga2/services_template.conf index 7ee5b30..1450bfe 100644 --- a/bundles/icinga2/files/icinga2/services_template.conf +++ b/bundles/icinga2/files/icinga2/services_template.conf @@ -14,6 +14,7 @@ object Service "${service}" { % endif % endif % endfor + vars.bundle = "${bundle_name}" vars.notification.sms = ${str(config.get('vars.notification.sms', False)).lower()} } % endfor diff --git a/bundles/icinga2/items.py b/bundles/icinga2/items.py index 006eded..5cd1c97 100644 --- a/bundles/icinga2/items.py +++ b/bundles/icinga2/items.py @@ -129,16 +129,6 @@ files = { 'svc_systemd:icinga2:restart', }, }, - '/etc/icinga2/conf.d/groups.conf': { - 'source': 'icinga2/groups.conf', - 'content_type': 'mako', - 'needs': { - 'pkg_apt:icinga2', - }, - 'triggers': { - 'svc_systemd:icinga2:restart', - }, - }, '/etc/icinga2/conf.d/templates.conf': { 'source': 'icinga2/templates.conf', 'needs': { @@ -261,6 +251,7 @@ for bundle, metadata in bundle_metadata.items(): 'source': 'icinga2/services_template.conf', 'content_type': 'mako', 'context': { + 'bundle_name': bundle, 'bundle_metadata': metadata['services'], }, 'owner': 'nagios', @@ -285,3 +276,16 @@ files['/etc/icinga2/conf.d/hosts.conf'] = { 'svc_systemd:icinga2:restart', }, } +files['/etc/icinga2/conf.d/groups.conf'] = { + 'source': 'icinga2/groups.conf', + 'content_type': 'mako', + 'context': { + 'bundles': bundle_metadata.keys(), + }, + 'needs': { + 'pkg_apt:icinga2', + }, + 'triggers': { + 'svc_systemd:icinga2:restart', + }, +}