source: genesis/tools/yaml2nag.py@ 11508

Last change on this file since 11508 was 11262, checked in by richardvm, 12 years ago

aangepast door huub, geen problemen mee

  • 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 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'] or datadump['nodetype'] == "Hybrid":
59 if datadump['nodetype'] in ['CNode', 'Hybrid']:
60 datadump['use'] = 'host-pnp'
61 hostgroups.append('nodes-ileiden')
62
63 print_host(datadump, hostgroups)
64 elif datadump['nodetype'] == 'Proxy':
65 datadump['use'] = 'host-proxy'
66 hostgroups.append('proxies')
67
68 print_host(datadump, hostgroups)
69 else:
70 print "# ERROR: nodetype %(nodetype)s for %(autogen_realname)s not defined" % datadump
71
72
73
Note: See TracBrowser for help on using the repository browser.