source: genesis/tools/yaml2nag.py@ 10932

Last change on this file since 10932 was 10911, checked in by richardvm, 13 years ago

dhcp configuratie standaard was veranderd

  • Property svn:executable set to *
File size: 1.9 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
9
10def is_ap(ifacedump):
11# return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == 'no'
12 return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == False
13
14def is_iris(node):
15 return node.has_key('release') and node['release'] in ['8.0-RELEASE', '7.2-RELEASE', '8.1-RELEASE', '8.2-RELEASE', '9.0-RELEASE']
16
17def is_up(datadump):
18 return datadump['status'] == 'up'
19
20
21
22def print_host(datadump, hostgroups):
23 datadump['hostgroups'] = ','.join(hostgroups)
24 print """
25define host{
26 use %(use)s
27 host_name %(autogen_realname)s
28 alias %(autogen_realname)s
29 address %(masterip)s
30 hostgroups %(hostgroups)s
31}
32""" % datadump
33
34
35if __name__ == '__main__':
36 # Process all hosts
37 for host in gformat.get_hostlist():
38 datadump = gformat.get_yaml(host)
39
40 # Make sure to process only active IRIS nodes
41 if not is_iris(datadump) or not is_up(datadump):
42 continue
43
44 hostgroups = []
45 if datadump['nodetype'] in ['CNode', 'Hybrid']:
46 datadump['use'] = 'host-pnp'
47 hostgroups.append('nodes-7-2')
48
49 # Interface groups
50 for iface in datadump['autogen_iface_keys']:
51 ifacedump = datadump[iface]
52 if is_up(ifacedump) and not is_ap(ifacedump):
53 key = 'iface-%s' % ifacedump['autogen_ifname']
54 if not key in hostgroups:
55 hostgroups.append(key)
56
57 # ileiden groups
58 if datadump['ileiden']:
59 hostgroups.append('nodes-ileiden')
60
61 print_host(datadump, hostgroups)
62 elif datadump['nodetype'] == 'Proxy':
63 datadump['use'] = 'host-proxy'
64 hostgroups.append('proxies')
65
66 print_host(datadump, hostgroups)
67 else:
68 print "# ERROR: nodetype %(nodetype)s for %(autogen_realname)s not defined" % datadump
69
70
71
Note: See TracBrowser for help on using the repository browser.