2021-04-02 16:57:13 +00:00
|
|
|
repo.libs.tools.require_bundle(node, 'postgresql')
|
|
|
|
repo.libs.tools.require_bundle(node, 'sshmon')
|
2020-11-10 11:40:12 +00:00
|
|
|
|
2020-11-10 12:43:46 +00:00
|
|
|
from os.path import join
|
|
|
|
|
2020-11-21 09:29:36 +00:00
|
|
|
ENABLED_FEATURES = {
|
|
|
|
'api',
|
|
|
|
'checker',
|
|
|
|
'ido-pgsql',
|
|
|
|
'mainlog',
|
|
|
|
'notification',
|
|
|
|
}
|
|
|
|
|
2020-11-22 12:28:14 +00:00
|
|
|
DAYS_TO_STRING = [
|
|
|
|
'sunday',
|
|
|
|
'monday',
|
|
|
|
'tuesday',
|
|
|
|
'wednesday',
|
|
|
|
'thursday',
|
|
|
|
'friday',
|
|
|
|
'saturday',
|
|
|
|
'sunday',
|
|
|
|
]
|
|
|
|
|
2020-11-21 07:57:46 +00:00
|
|
|
directories = {
|
|
|
|
'/etc/icingaweb2': {
|
|
|
|
'group': 'icingaweb2',
|
2022-03-12 07:53:48 +00:00
|
|
|
'mode': '2770',
|
2020-11-21 07:57:46 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icingaweb2',
|
|
|
|
},
|
|
|
|
},
|
2020-11-21 09:29:36 +00:00
|
|
|
'/etc/icinga2/features-enabled': {
|
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2021-08-07 05:13:41 +00:00
|
|
|
'mode': '0750',
|
2020-11-21 09:29:36 +00:00
|
|
|
'purge': True,
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2-ido-pgsql',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/icinga2/conf.d': {
|
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2021-08-07 05:13:41 +00:00
|
|
|
'mode': '0750',
|
2020-11-21 09:29:36 +00:00
|
|
|
'purge': True,
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
2022-02-18 11:25:34 +00:00
|
|
|
'/etc/icinga2/conf.d/hosts': {
|
2020-11-21 09:29:36 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2021-08-07 05:13:41 +00:00
|
|
|
'mode': '0750',
|
2020-11-21 09:29:36 +00:00
|
|
|
'purge': True,
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-21 07:57:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 11:40:12 +00:00
|
|
|
files = {
|
2020-11-21 09:29:36 +00:00
|
|
|
### Checks
|
2020-11-10 11:40:12 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_by_sshmon': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-11-22 10:38:53 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_sipgate_account_balance': {
|
|
|
|
'mode': '0755',
|
|
|
|
'content_type': 'mako',
|
2021-09-16 17:29:52 +00:00
|
|
|
'cascade_skip': False, # contains faults
|
2020-11-22 10:38:53 +00:00
|
|
|
},
|
2021-01-09 10:03:23 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_freifunk_node': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2022-01-02 13:50:32 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_imap_for_mail_from': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2021-11-28 06:26:41 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_spam_blocklist': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2021-04-25 06:02:04 +00:00
|
|
|
'/usr/local/share/icinga/plugins/check_usv_snmp': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-11-10 12:43:46 +00:00
|
|
|
'/etc/sshmon.priv': {
|
|
|
|
'content': repo.vault.decrypt_file(join('sshmon', 'sshmon.key.vault')),
|
2020-11-13 12:19:26 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-10 12:43:46 +00:00
|
|
|
'mode': '0400',
|
2020-11-13 12:19:26 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2-ido-pgsql',
|
|
|
|
},
|
2020-11-21 07:57:46 +00:00
|
|
|
},
|
2020-11-21 09:29:36 +00:00
|
|
|
|
|
|
|
# Icinga2
|
|
|
|
'/etc/icinga2/icinga2.conf': {
|
|
|
|
'source': 'icinga2/icinga2.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-22 08:04:02 +00:00
|
|
|
'/etc/icinga2/scripts/icinga_notification_wrapper': {
|
|
|
|
'source': 'scripts/icinga_notification_wrapper',
|
2020-11-22 09:34:49 +00:00
|
|
|
'content_type': 'mako',
|
2020-11-22 08:04:02 +00:00
|
|
|
'mode': '0755',
|
2021-12-24 15:29:18 +00:00
|
|
|
'cascade_skip': False, # contains faults
|
2020-11-22 08:04:02 +00:00
|
|
|
},
|
2020-11-21 09:29:36 +00:00
|
|
|
'/etc/icinga2/features-available/ido-pgsql.conf': {
|
|
|
|
'source': 'icinga2/ido-pgsql.conf',
|
|
|
|
'content_type': 'mako',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/icinga2/conf.d/api-users.conf': {
|
|
|
|
'source': 'icinga2/api-users.conf',
|
|
|
|
'content_type': 'mako',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/icinga2/conf.d/app.conf': {
|
|
|
|
'source': 'icinga2/app.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/icinga2/conf.d/check_commands.conf': {
|
|
|
|
'source': 'icinga2/check_commands.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
2022-02-18 11:25:34 +00:00
|
|
|
'/etc/icinga2/conf.d/hosts.conf': {
|
|
|
|
'source': 'icinga2/hosts.conf',
|
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-22 08:04:02 +00:00
|
|
|
'/etc/icinga2/conf.d/notification_commands.conf': {
|
|
|
|
'source': 'icinga2/notification_commands.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-22 08:04:02 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/icinga2/conf.d/notifications.conf': {
|
|
|
|
'source': 'icinga2/notifications.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-22 08:04:02 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-21 09:29:36 +00:00
|
|
|
'/etc/icinga2/conf.d/templates.conf': {
|
|
|
|
'source': 'icinga2/templates.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/icinga2/conf.d/timeperiods.conf': {
|
|
|
|
'source': 'icinga2/timeperiods.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/icinga2/conf.d/users.conf': {
|
|
|
|
'source': 'icinga2/users.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'content_type': 'mako',
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
# IcingaWeb2
|
|
|
|
'/etc/icingaweb2/authentication.ini': {
|
|
|
|
'source': 'icingaweb2/authentication.ini',
|
|
|
|
'mode': '0660',
|
|
|
|
'group': 'icingaweb2',
|
|
|
|
},
|
|
|
|
'/etc/icingaweb2/config.ini': {
|
|
|
|
'source': 'icingaweb2/config.ini',
|
|
|
|
'mode': '0660',
|
|
|
|
'group': 'icingaweb2',
|
|
|
|
},
|
|
|
|
'/etc/icingaweb2/groups.ini': {
|
|
|
|
'source': 'icingaweb2/groups.ini',
|
2020-11-21 07:57:46 +00:00
|
|
|
'mode': '0660',
|
|
|
|
'group': 'icingaweb2',
|
|
|
|
},
|
2020-11-21 09:29:36 +00:00
|
|
|
'/etc/icingaweb2/resources.ini': {
|
|
|
|
'source': 'icingaweb2/resources.ini',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'mode': '0660',
|
|
|
|
'group': 'icingaweb2',
|
|
|
|
},
|
2020-11-22 17:53:57 +00:00
|
|
|
|
|
|
|
# Statusmonitor
|
|
|
|
'/etc/icinga2/icinga_statusmonitor.py': {
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga_statusmonitor:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/systemd/system/icinga_statusmonitor.service': {
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
|
|
|
'svc_systemd:icinga_statusmonitor:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-21 09:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
'icinga2_api_setup': {
|
|
|
|
'command': 'icinga2 api setup',
|
|
|
|
'unless': 'test -e /var/lib/icinga2/certs/{}.crt'.format(node.metadata['hostname']),
|
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for feature in ENABLED_FEATURES:
|
|
|
|
symlinks[f'/etc/icinga2/features-enabled/{feature}.conf'] = {
|
|
|
|
'target': f'/etc/icinga2/features-available/{feature}.conf',
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 09:29:36 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-01-30 16:31:05 +00:00
|
|
|
icinga_run_deps = {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
'pkg_apt:icinga2-ido-pgsql',
|
|
|
|
}
|
2021-02-12 19:37:36 +00:00
|
|
|
for name in actions:
|
2021-01-30 16:31:05 +00:00
|
|
|
icinga_run_deps.add(f'action:{name}')
|
2021-02-12 19:37:36 +00:00
|
|
|
for name in directories:
|
2021-01-30 16:31:05 +00:00
|
|
|
icinga_run_deps.add(f'directory:{name}')
|
2021-02-12 19:37:36 +00:00
|
|
|
for name in files:
|
2021-01-30 16:31:05 +00:00
|
|
|
icinga_run_deps.add(f'file:{name}')
|
2021-02-12 19:37:36 +00:00
|
|
|
for name in symlinks:
|
2021-01-30 16:31:05 +00:00
|
|
|
icinga_run_deps.add(f'symlink:{name}')
|
|
|
|
|
2020-11-21 09:29:36 +00:00
|
|
|
svc_systemd = {
|
|
|
|
'icinga2': {
|
2021-01-30 16:31:05 +00:00
|
|
|
'needs': icinga_run_deps,
|
2020-11-21 09:29:36 +00:00
|
|
|
},
|
2020-11-22 17:53:57 +00:00
|
|
|
'icinga_statusmonitor': {
|
|
|
|
'needs': {
|
|
|
|
'file:/etc/icinga2/icinga_statusmonitor.py',
|
|
|
|
'file:/etc/systemd/system/icinga_statusmonitor.service',
|
|
|
|
'pkg_apt:python3-flask',
|
|
|
|
},
|
|
|
|
},
|
2020-11-21 09:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# The actual hosts and services management starts here
|
2022-02-18 11:25:34 +00:00
|
|
|
bundles = set()
|
|
|
|
for rnode in repo.nodes:
|
|
|
|
if rnode.metadata.get('icinga_options/exclude_from_monitoring', False):
|
|
|
|
continue
|
2020-11-21 09:29:36 +00:00
|
|
|
|
2022-02-18 11:25:34 +00:00
|
|
|
files[f'/etc/icinga2/conf.d/hosts/{rnode.name}.conf'] = {
|
|
|
|
'source': 'icinga2/hosts_template.conf',
|
2020-11-21 09:29:36 +00:00
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
2022-02-18 11:25:34 +00:00
|
|
|
'rnode': rnode,
|
2020-11-21 09:29:36 +00:00
|
|
|
},
|
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2022-01-02 13:50:32 +00:00
|
|
|
'cascade_skip': False, # may contain faults
|
2020-11-21 09:29:36 +00:00
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-02-18 11:25:34 +00:00
|
|
|
bundles |= set(rnode.metadata.get('icinga2_api', {}).keys())
|
|
|
|
|
2020-11-21 22:04:15 +00:00
|
|
|
files['/etc/icinga2/conf.d/groups.conf'] = {
|
|
|
|
'source': 'icinga2/groups.conf',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
2022-02-18 11:25:34 +00:00
|
|
|
'bundles': bundles,
|
2020-11-21 22:04:15 +00:00
|
|
|
},
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-21 22:04:15 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
}
|
2022-02-18 11:25:34 +00:00
|
|
|
|
2020-11-22 12:28:14 +00:00
|
|
|
files['/etc/icinga2/conf.d/downtimes.conf'] = {
|
|
|
|
'source': 'icinga2/downtimes.conf',
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': {
|
|
|
|
'days': DAYS_TO_STRING,
|
|
|
|
},
|
2021-08-07 05:13:41 +00:00
|
|
|
'owner': 'nagios',
|
|
|
|
'group': 'nagios',
|
2020-11-22 12:28:14 +00:00
|
|
|
'needs': {
|
|
|
|
'pkg_apt:icinga2',
|
|
|
|
},
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:icinga2:restart',
|
|
|
|
},
|
|
|
|
}
|