#!/usr/bin/env python # # Script to create nagios output files from gformat configurtion files # # Original: Richard van Mansom # Rick van der Zwet import gformat NODE_PREFIX = 'nodes-7-2' def is_ap(ifacedump): return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == 'no' def is_iris(node): return node.has_key('release') and node['release'] in ['8.0-RELEASE', '7.2-RELEASE', '8.1-RELEASE', '8.2-RELEASE'] if __name__ == '__main__': for host in gformat.get_hostlist(): datadump = gformat.get_yaml(host) # Make sure to process only active IRIS nodes if not is_iris(datadump) or not datadump['status'] == 'up': continue # Default hostgroup hostgroups = [NODE_PREFIX,] # Interface groups for iface in datadump['autogen_iface_keys']: ifacedump = datadump[iface] if (ifacedump['status'] == 'up' and not is_ap(ifacedump)): key = 'iface-%s' % ifacedump['autogen_ifname'] if not key in hostgroups: hostgroups.append(key) if datadump['ileiden']: hostgroups.append('node-ileiden') datadump['hostgroups'] = ','.join(hostgroups) print """ define host{ use host-pnp host_name %(nodename)s alias %(nodename)s address %(masterip)s hostgroups %(hostgroups)s } """ % datadump