bundles/icinga2: rework config generation - use one file per host instead of one per bundle
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit
This commit is contained in:
parent
5aa9f50c79
commit
d35770c122
5 changed files with 82 additions and 101 deletions
|
@ -59,7 +59,7 @@ directories = {
|
|||
'svc_systemd:icinga2:restart',
|
||||
},
|
||||
},
|
||||
'/etc/icinga2/conf.d/services': {
|
||||
'/etc/icinga2/conf.d/hosts': {
|
||||
'owner': 'nagios',
|
||||
'group': 'nagios',
|
||||
'mode': '0750',
|
||||
|
@ -169,6 +169,17 @@ files = {
|
|||
'svc_systemd:icinga2:restart',
|
||||
},
|
||||
},
|
||||
'/etc/icinga2/conf.d/hosts.conf': {
|
||||
'source': 'icinga2/hosts.conf',
|
||||
'owner': 'nagios',
|
||||
'group': 'nagios',
|
||||
'needs': {
|
||||
'pkg_apt:icinga2',
|
||||
},
|
||||
'triggers': {
|
||||
'svc_systemd:icinga2:restart',
|
||||
},
|
||||
},
|
||||
'/etc/icinga2/conf.d/notification_commands.conf': {
|
||||
'source': 'icinga2/notification_commands.conf',
|
||||
'owner': 'nagios',
|
||||
|
@ -319,38 +330,17 @@ svc_systemd = {
|
|||
|
||||
|
||||
# The actual hosts and services management starts here
|
||||
monitored_nodes = repo.nodes
|
||||
bundles = set()
|
||||
for rnode in repo.nodes:
|
||||
if rnode.metadata.get('icinga_options/exclude_from_monitoring', False):
|
||||
continue
|
||||
|
||||
for n in monitored_nodes[:]:
|
||||
if n.metadata.get('icinga_options/exclude_from_monitoring', False):
|
||||
monitored_nodes.remove(n)
|
||||
|
||||
bundle_metadata = {}
|
||||
for monitored_node in monitored_nodes:
|
||||
node_metadata = monitored_node.metadata
|
||||
|
||||
for bundle, config in sorted(node_metadata.get('icinga2_api', {}).items()):
|
||||
if bundle not in bundle_metadata:
|
||||
bundle_metadata[bundle] = {
|
||||
'services': {}
|
||||
}
|
||||
|
||||
bundle_metadata[bundle]['services'].update({
|
||||
monitored_node: config['services']
|
||||
})
|
||||
|
||||
for serv, conf in bundle_metadata[bundle]['services'][monitored_node].items():
|
||||
if 'check_command' not in conf:
|
||||
# This default is also set in sshmon bundle
|
||||
conf['check_command'] = 'sshmon'
|
||||
|
||||
for bundle, metadata in bundle_metadata.items():
|
||||
files[f'/etc/icinga2/conf.d/services/{bundle}.conf'] = {
|
||||
'source': 'icinga2/services_template.conf',
|
||||
files[f'/etc/icinga2/conf.d/hosts/{rnode.name}.conf'] = {
|
||||
'source': 'icinga2/hosts_template.conf',
|
||||
'content_type': 'mako',
|
||||
'context': {
|
||||
'bundle_name': bundle,
|
||||
'bundle_metadata': metadata['services'],
|
||||
'rnode': rnode,
|
||||
'sla_info': SLA_INFO,
|
||||
},
|
||||
'owner': 'nagios',
|
||||
'group': 'nagios',
|
||||
|
@ -360,24 +350,13 @@ for bundle, metadata in bundle_metadata.items():
|
|||
},
|
||||
}
|
||||
|
||||
files['/etc/icinga2/conf.d/hosts.conf'] = {
|
||||
'source': 'icinga2/hosts.conf',
|
||||
'content_type': 'mako',
|
||||
'context': {
|
||||
'monitored_nodes': monitored_nodes,
|
||||
'sla_info': SLA_INFO,
|
||||
},
|
||||
'owner': 'nagios',
|
||||
'group': 'nagios',
|
||||
'triggers': {
|
||||
'svc_systemd:icinga2:restart',
|
||||
},
|
||||
}
|
||||
bundles |= set(rnode.metadata.get('icinga2_api', {}).keys())
|
||||
|
||||
files['/etc/icinga2/conf.d/groups.conf'] = {
|
||||
'source': 'icinga2/groups.conf',
|
||||
'content_type': 'mako',
|
||||
'context': {
|
||||
'bundles': bundle_metadata.keys(),
|
||||
'bundles': bundles,
|
||||
},
|
||||
'owner': 'nagios',
|
||||
'group': 'nagios',
|
||||
|
@ -388,11 +367,11 @@ 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,
|
||||
},
|
||||
'owner': 'nagios',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue