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