bundles/icinga2: use ip addresses for monitoring instead of hostnames
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit

This commit is contained in:
Franzi 2022-03-13 15:15:47 +01:00
parent 5179edb458
commit 7604fef734
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 32 additions and 5 deletions

View file

@ -340,11 +340,33 @@ for rnode in repo.nodes:
if rnode.metadata.get('icinga_options/exclude_from_monitoring', False):
continue
host_ips = repo.libs.tools.resolve_identifier(repo, rnode.name)
icinga_ips = {}
# XXX for the love of god, PLEASE remove this once DNS is no longer
# hosted at GCE
if rnode.in_group('gce'):
icinga_ips['ipv4'] = rnode.metadata.get('external_ipv4')
else:
for ip_type in ('ipv4', 'ipv6'):
for ip in sorted(host_ips[ip_type]):
if ip.is_private and not ip.is_link_local:
icinga_ips[ip_type] = str(ip)
break
else:
if host_ips[ip_type]:
icinga_ips[ip_type] = sorted(host_ips[ip_type])[0]
if not icinga_ips:
raise ValueError(f'{rnode.name} requests monitoring, but has neither IPv4 nor IPv6 addresses!')
files[f'/etc/icinga2/conf.d/hosts/{rnode.name}.conf'] = {
'source': 'icinga2/hosts_template.conf',
'content_type': 'mako',
'context': {
'rnode': rnode,
'address4': icinga_ips.get('ipv4', None),
'address6': icinga_ips.get('ipv6', None),
},
'owner': 'nagios',
'group': 'nagios',