source: genesis/tools/yaml2nag.py@ 13128

Last change on this file since 13128 was 11555, checked in by rick, 12 years ago

status in verplicht voor een interface, controleer hier dus op.

Fixes: beheer#268

  • Property svn:executable set to *
File size: 2.2 KB
RevLine 
[8644]1#!/usr/bin/env python
[10388]2#
3# Script to create nagios output files from gformat configurtion files
4#
5# Original: Richard van Mansom <richardvm@wirelessleiden.nl>
6# Rick van der Zwet <rick@wirelessleiden.nl>
[8644]7
[10388]8import gformat
[11555]9import logging
[8644]10
[11555]11logging.basicConfig(level=logging.DEBUG)
12logger = logging.getLogger()
13
[10388]14def is_ap(ifacedump):
[10911]15# return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == 'no'
16 return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == False
[8644]17
[10388]18def is_iris(node):
[10396]19 return node.has_key('release') and node['release'] in ['8.0-RELEASE', '7.2-RELEASE', '8.1-RELEASE', '8.2-RELEASE', '9.0-RELEASE']
[8644]20
[10393]21def is_up(datadump):
22 return datadump['status'] == 'up'
23
24
25
26def print_host(datadump, hostgroups):
27 datadump['hostgroups'] = ','.join(hostgroups)
28 print """
29define host{
30 use %(use)s
31 host_name %(autogen_realname)s
32 alias %(autogen_realname)s
33 address %(masterip)s
34 hostgroups %(hostgroups)s
35}
36""" % datadump
37
38
[10388]39if __name__ == '__main__':
[10393]40 # Process all hosts
[10388]41 for host in gformat.get_hostlist():
[11555]42 logger.debug("Processing host %s", host)
[10388]43 datadump = gformat.get_yaml(host)
[8644]44
[10388]45 # Make sure to process only active IRIS nodes
[10393]46 if not is_iris(datadump) or not is_up(datadump):
[10388]47 continue
[8644]48
[10393]49 hostgroups = []
[10695]50 if datadump['nodetype'] in ['CNode', 'Hybrid']:
[10393]51 datadump['use'] = 'host-pnp'
52 hostgroups.append('nodes-7-2')
[8644]53
[10393]54 # Interface groups
55 for iface in datadump['autogen_iface_keys']:
56 ifacedump = datadump[iface]
57 if is_up(ifacedump) and not is_ap(ifacedump):
58 key = 'iface-%s' % ifacedump['autogen_ifname']
59 if not key in hostgroups:
60 hostgroups.append(key)
[8644]61
[10393]62 # ileiden groups
[11262]63# if datadump['ileiden'] or datadump['nodetype'] == "Hybrid":
64 if datadump['nodetype'] in ['CNode', 'Hybrid']:
65 datadump['use'] = 'host-pnp'
[10393]66 hostgroups.append('nodes-ileiden')
[8644]67
[11262]68 print_host(datadump, hostgroups)
69 elif datadump['nodetype'] == 'Proxy':
70 datadump['use'] = 'host-proxy'
71 hostgroups.append('proxies')
[10393]72
[11262]73 print_host(datadump, hostgroups)
74 else:
75 print "# ERROR: nodetype %(nodetype)s for %(autogen_realname)s not defined" % datadump
[10393]76
77
78
Note: See TracBrowser for help on using the repository browser.