[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):
|
---|
[10911] | 11 | # return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == 'no'
|
---|
| 12 | return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == False
|
---|
[8644] | 13 |
|
---|
[10388] | 14 | def is_iris(node):
|
---|
[10396] | 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']
|
---|
[8644] | 16 |
|
---|
[10393] | 17 | def is_up(datadump):
|
---|
| 18 | return datadump['status'] == 'up'
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | def print_host(datadump, hostgroups):
|
---|
| 23 | datadump['hostgroups'] = ','.join(hostgroups)
|
---|
| 24 | print """
|
---|
| 25 | define 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 |
|
---|
[10388] | 35 | if __name__ == '__main__':
|
---|
[10393] | 36 | # Process all hosts
|
---|
[10388] | 37 | for host in gformat.get_hostlist():
|
---|
| 38 | datadump = gformat.get_yaml(host)
|
---|
[8644] | 39 |
|
---|
[10388] | 40 | # Make sure to process only active IRIS nodes
|
---|
[10393] | 41 | if not is_iris(datadump) or not is_up(datadump):
|
---|
[10388] | 42 | continue
|
---|
[8644] | 43 |
|
---|
[10393] | 44 | hostgroups = []
|
---|
[10695] | 45 | if datadump['nodetype'] in ['CNode', 'Hybrid']:
|
---|
[10393] | 46 | datadump['use'] = 'host-pnp'
|
---|
| 47 | hostgroups.append('nodes-7-2')
|
---|
[8644] | 48 |
|
---|
[10393] | 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)
|
---|
[8644] | 56 |
|
---|
[10393] | 57 | # ileiden groups
|
---|
| 58 | if datadump['ileiden']:
|
---|
| 59 | hostgroups.append('nodes-ileiden')
|
---|
[8644] | 60 |
|
---|
[10393] | 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 |
|
---|