source: genesis/tools/yaml2nag-nano.py@ 10896

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

rivisioned version of: yaml2nag.py
creates a list for nagios's nanostations

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