source: genesis/tools/yaml2nag.py@ 13945

Last change on this file since 13945 was 13843, checked in by rick, 8 years ago

Fix generation & cleanup of config files

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/usr/bin/env python
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>
7
8import gformat
9import logging
10
11logging.basicConfig(level=logging.DEBUG)
12logger = logging.getLogger()
13
14def is_ap(ifacedump):
15# return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == 'no'
16 return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == False
17
18def is_iris(node):
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']
20
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_fqdn)s
32 alias %(autogen_fqdn)s
33 address %(masterip)s
34 hostgroups %(hostgroups)s
35}
36""" % datadump
37
38
39if __name__ == '__main__':
40 # Process all hosts
41 for host in gformat.get_hostlist():
42 logger.debug("Processing host %s", host)
43 datadump = gformat.get_yaml(host)
44
45 # Make sure to process only active IRIS nodes
46 if not is_iris(datadump) or not is_up(datadump):
47 continue
48
49 hostgroups = []
50 if datadump['nodetype'] in ['CNode', 'Hybrid']:
51 datadump['use'] = 'host-pnp'
52 hostgroups.append('nodes-7-2')
53
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)
61
62 # ileiden groups
63# if datadump['ileiden'] or datadump['nodetype'] == "Hybrid":
64 if datadump['nodetype'] in ['CNode', 'Hybrid']:
65 datadump['use'] = 'host-pnp'
66 hostgroups.append('nodes-ileiden')
67
68 print_host(datadump, hostgroups)
69 elif datadump['nodetype'] == 'Proxy':
70 datadump['use'] = 'host-proxy'
71 hostgroups.append('proxies')
72
73 print_host(datadump, hostgroups)
74 else:
75 print "# ERROR: nodetype %(nodetype)s for %(autogen_fqdn)s not defined" % datadump
76
77
78
Note: See TracBrowser for help on using the repository browser.