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

@ -9,7 +9,7 @@ object CheckCommand "sshmon" {
value = "$sshmon_command$" value = "$sshmon_command$"
} }
"-h" = { "-h" = {
value = "$address$" value = "$check_address$"
} }
"-t" = { "-t" = {
set_if = bool("$sshmon_timeout$") set_if = bool("$sshmon_timeout$")
@ -81,7 +81,7 @@ object CheckCommand "check_imap" {
value = "$imap_port$" value = "$imap_port$"
} }
"-H" = { "-H" = {
value = "$address$" value = "$check_address$"
} }
} }
} }
@ -108,7 +108,7 @@ object CheckCommand "check_smtp" {
arguments = { arguments = {
"-H" = { "-H" = {
value = "$address$" value = "$check_address$"
} }
} }
} }
@ -124,6 +124,6 @@ object CheckCommand "check_usv" {
import "plugin-check-command" import "plugin-check-command"
import "ipv4-or-ipv6" import "ipv4-or-ipv6"
command = [ "/usr/local/share/icinga/plugins/check_usv_snmp", "$address$", "$snmp_community$" ] command = [ "/usr/local/share/icinga/plugins/check_usv_snmp", "$check_address$", "$snmp_community$" ]
vars.snmp_community = "public" vars.snmp_community = "public"
} }

View file

@ -1,7 +1,12 @@
object Host "${rnode.name}" { object Host "${rnode.name}" {
import "generic-host" import "generic-host"
address = "${rnode.metadata.get('icinga_options/hostname', rnode.hostname)}" % if address4:
address = "${address4}"
% endif
% if address6:
address6 = "${address6}"
% endif
# used for determining service groups # used for determining service groups
vars.bw_groups = [ "${'", "'.join(sorted({group.name for group in rnode.groups}))}" ] vars.bw_groups = [ "${'", "'.join(sorted({group.name for group in rnode.groups}))}" ]

View file

@ -340,11 +340,33 @@ for rnode in repo.nodes:
if rnode.metadata.get('icinga_options/exclude_from_monitoring', False): if rnode.metadata.get('icinga_options/exclude_from_monitoring', False):
continue 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'] = { files[f'/etc/icinga2/conf.d/hosts/{rnode.name}.conf'] = {
'source': 'icinga2/hosts_template.conf', 'source': 'icinga2/hosts_template.conf',
'content_type': 'mako', 'content_type': 'mako',
'context': { 'context': {
'rnode': rnode, 'rnode': rnode,
'address4': icinga_ips.get('ipv4', None),
'address6': icinga_ips.get('ipv6', None),
}, },
'owner': 'nagios', 'owner': 'nagios',
'group': 'nagios', 'group': 'nagios',