From 4a57926577c24489d658fa6bd06130fa03f97d7b Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 22 Nov 2020 08:24:44 +0100 Subject: [PATCH] bundles/icinga2: set some notification options for checks --- bundles/icinga2/files/icinga2/groups.conf | 12 ++++++++++++ bundles/icinga2/files/icinga2/hosts.conf | 2 ++ bundles/icinga2/files/icinga2/templates.conf | 8 -------- bundles/nginx/metadata.py | 2 ++ bundles/postfix/metadata.py | 1 + bundles/powerdns/metadata.py | 1 + bundles/sshmon/metadata.py | 1 + bundles/vmhost/metadata.py | 1 + bundles/zfs/metadata.py | 5 ++++- nodes/htz-cloud/sewfile.py | 3 +++ 10 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bundles/icinga2/files/icinga2/groups.conf b/bundles/icinga2/files/icinga2/groups.conf index f621295..7b0ba72 100644 --- a/bundles/icinga2/files/icinga2/groups.conf +++ b/bundles/icinga2/files/icinga2/groups.conf @@ -13,3 +13,15 @@ object ServiceGroup "bundle-${bundle}" { assign where service.vars.bundle == "${bundle}" } % endfor + +object ServiceGroup "checks_with_mail" { + display_name = "Checks which send E-Mails" + + assign where service.vars.notification.mail == true +} + +object ServiceGroup "checks_with_sms" { + display_name = "Checks which send SMS" + + assign where service.vars.notification.sms == true +} diff --git a/bundles/icinga2/files/icinga2/hosts.conf b/bundles/icinga2/files/icinga2/hosts.conf index 47b10dd..c4e5f1f 100644 --- a/bundles/icinga2/files/icinga2/hosts.conf +++ b/bundles/icinga2/files/icinga2/hosts.conf @@ -9,6 +9,8 @@ object Host "${monitored_node.name}" { vars.period = "${sla_info[monitored_node.metadata.get('sla', '24x7')]}" vars.location = "${monitored_node.metadata.get('location', 'unknown')}" vars.bw_groups = [ "${'", "'.join(sorted({group.name for group in monitored_node.groups}))}" ] + vars.notification.sms = ${str(monitored_node.metadata.get('icinga_options', {}).get('vars.notification.sms', True)).lower()} + vars.notification.mail = true } % endfor diff --git a/bundles/icinga2/files/icinga2/templates.conf b/bundles/icinga2/files/icinga2/templates.conf index b1865e0..5bc6255 100644 --- a/bundles/icinga2/files/icinga2/templates.conf +++ b/bundles/icinga2/files/icinga2/templates.conf @@ -7,9 +7,6 @@ template Host "generic-host" { enable_event_handler = true enable_flapping = false enable_perfdata = false - vars.notification.sms = true - vars.notification_type = "sms" - } template Host "host-active" { @@ -36,7 +33,6 @@ template Service "generic-service" { max_check_attempts = 4 check_interval = 5m retry_interval = 2m - vars.notification.sms = true enable_notifications = true enable_event_handler = true enable_flapping = false @@ -63,8 +59,6 @@ template Notification "host-notification" { types = [ Problem, Recovery, Custom ] user_groups = [ "on-call_sms" ] period = host.vars.period - - vars.notification_type = "sms" } template Notification "service-notification" { @@ -73,8 +67,6 @@ template Notification "service-notification" { types = [ Problem, Recovery, Custom ] user_groups = [ "on-call_sms" ] - vars.notification_type = "sms" - if(service.vars.period) { period = service.vars.period } else { diff --git a/bundles/nginx/metadata.py b/bundles/nginx/metadata.py index fffd16d..fb7681a 100644 --- a/bundles/nginx/metadata.py +++ b/bundles/nginx/metadata.py @@ -106,12 +106,14 @@ def monitoring(metadata): 'check_command': 'check_http_wget', 'vars.http_wget_contains': vconfig['website_check_string'], 'vars.http_wget_url': '{}://{}{}'.format(scheme, domain, vconfig['website_check_path']), + 'vars.notification.sms': True, } if vconfig.get('check_ssl', False): services['NGINX VHOST {} CERTIFICATE'.format(vname)] = { 'check_command': 'check_vhost_https_cert_at_url', 'vars.domain': domain, + 'vars.notification.mail': True, } max_connections = metadata.get('nginx/worker_connections') * metadata.get('nginx/worker_processes') diff --git a/bundles/postfix/metadata.py b/bundles/postfix/metadata.py index d229ef4..aa1e5bf 100644 --- a/bundles/postfix/metadata.py +++ b/bundles/postfix/metadata.py @@ -28,6 +28,7 @@ if node.has_bundle('postfixadmin'): defaults['icinga2_api']['postfix']['services'].update({ 'SMTP CONNECT': { 'check_command': 'check_smtp', + 'vars.notification.sms': True, }, 'SMTP SUBMISSION CONNECT': { 'check_command': 'check_smtp', diff --git a/bundles/powerdns/metadata.py b/bundles/powerdns/metadata.py index 3b7b338..b668fb9 100644 --- a/bundles/powerdns/metadata.py +++ b/bundles/powerdns/metadata.py @@ -14,6 +14,7 @@ defaults = { 'services': { 'POWERDNS PROCESS': { 'command_on_monitored_host': '/usr/lib/nagios/plugins/check_procs -C pdns_server -c 1:', + 'vars.notification.mail': True, }, }, }, diff --git a/bundles/sshmon/metadata.py b/bundles/sshmon/metadata.py index 7ab32ca..47c6338 100644 --- a/bundles/sshmon/metadata.py +++ b/bundles/sshmon/metadata.py @@ -96,6 +96,7 @@ def default_checks(metadata): '-A -I "^/dev$" -I "^/run" -I "^/sys" -i "/sys/kernel/debug/tracing" ' f'{disk_space_ignore_patterns_string}', ), + 'vars.notification.mail': True, }, 'MOUNTS': { 'command_on_monitored_host': f'sudo /usr/local/share/icinga/plugins/check_mounts {mounts_options}', diff --git a/bundles/vmhost/metadata.py b/bundles/vmhost/metadata.py index 424bad9..2bd660e 100644 --- a/bundles/vmhost/metadata.py +++ b/bundles/vmhost/metadata.py @@ -12,6 +12,7 @@ defaults = { 'services': { 'QEMU VM STATUS': { 'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_vm_status', + 'vars.notification.mail': True, }, }, }, diff --git a/bundles/zfs/metadata.py b/bundles/zfs/metadata.py index 81970cc..5636dea 100644 --- a/bundles/zfs/metadata.py +++ b/bundles/zfs/metadata.py @@ -76,6 +76,7 @@ if node.has_bundle('sshmon'): }, 'ZFS MOUNTED VOLUMES': { 'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zfs_volumes', + 'vars.notification.mail': True, }, 'ZFS OLD SNAPSHOTS': { 'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zfs_old_snapshots', @@ -147,10 +148,12 @@ def monitoring(metadata): for poolname, pool_options in metadata.get('zfs/pools').items(): services['ZFS ZPOOL ONLINE {}'.format(poolname)] = { 'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zpool_online {}'.format(poolname), + 'vars.notification.mail': True, } services['ZFS ZPOOL SPACE ' + poolname] = { - 'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zpool_space {} 90'.format(poolname) + 'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zpool_space {} 90'.format(poolname), + 'vars.notification.mail': True, } return { diff --git a/nodes/htz-cloud/sewfile.py b/nodes/htz-cloud/sewfile.py index 3ae5115..e9f1ee6 100644 --- a/nodes/htz-cloud/sewfile.py +++ b/nodes/htz-cloud/sewfile.py @@ -10,6 +10,9 @@ nodes['htz-cloud.sewfile'] = { 'webserver', }, 'metadata': { + 'icinga_options': { + 'vars.notification.sms': False, + }, 'interfaces': { 'eth0': { 'ips': {