from bundlewrap.metadata import atomic defaults = { 'icinga2_api': { 'bind': { 'services': { 'BIND PROCESS': { 'command_on_monitored_host': '/usr/lib/nagios/plugins/check_procs -C named -c 1:1', }, }, }, }, } @metadata_reactor def port_checks(metadata): services = {} for interface in metadata.get('bind/listen', set()): services[f'BIND PORT {interface}'] = { 'check_command': 'tcp', 'vars.tcp_address': metadata.get(f'interfaces/{interface}/ip_addresses')[0], 'vars.tcp_port': 53, } return { 'icinga2_api': { 'bind': { 'services': services, }, }, } @metadata_reactor def generate_dns_entries_for_nodes(metadata): results = set() for rnode in repo.nodes: node_name_split = rnode.name.split('.') node_name_split.reverse() dns_name = '.'.join(node_name_split) ip4 = None ip6 = None # We only need this for GCE, because machines over there don't # have a public ipv4 address. if rnode.metadata.get('external_ipv4', None): ip4 = rnode.metadata.get('external_ipv4') for iface, config in sorted(rnode.metadata.get('interfaces', {}).items()): if not ip4 and 'ipv4' in config: ip4 = sorted(config['ipv4'])[0] if not ip6 and 'ipv6' in config: ip6 = sorted(config['ipv6'])[0] if ip4: results.add('{} IN A {}'.format(dns_name, ip4)) if ip6: results.add('{} IN AAAA {}'.format(dns_name, ip6)) return { 'bind': { 'zones_primary': { 'kunbox.net': { 'records': results, }, }, }, }