Merge pull request #41349 from garethgreenaway/update_network_info_beacon

Fixes to network_info beacon
This commit is contained in:
Mike Place 2017-05-26 16:51:39 -05:00 committed by GitHub
commit 0b6f8437cf

View File

@ -34,8 +34,8 @@ def _to_list(obj):
ret = {}
for attr in __attrs:
# Better way to do this?
ret[attr] = obj.__dict__[attr]
if hasattr(obj, attr):
ret[attr] = getattr(obj, attr)
return ret
@ -86,16 +86,16 @@ def beacon(config):
beacons:
network_info:
eth0:
- type: equal
- bytes_sent: 100000
- bytes_recv: 100000
- packets_sent: 100000
- packets_recv: 100000
- errin: 100
- errout: 100
- dropin: 100
- dropout: 100
- eth0:
type: equal
bytes_sent: 100000
bytes_recv: 100000
packets_sent: 100000
packets_recv: 100000
errin: 100
errout: 100
dropin: 100
dropout: 100
Emit beacon when any values are greater
than configured values.
@ -104,16 +104,16 @@ def beacon(config):
beacons:
network_info:
eth0:
- type: greater
- bytes_sent: 100000
- bytes_recv: 100000
- packets_sent: 100000
- packets_recv: 100000
- errin: 100
- errout: 100
- dropin: 100
- dropout: 100
- eth0:
type: greater
bytes_sent: 100000
bytes_recv: 100000
packets_sent: 100000
packets_recv: 100000
errin: 100
errout: 100
dropin: 100
dropout: 100
'''
@ -121,20 +121,29 @@ def beacon(config):
_stats = psutil.net_io_counters(pernic=True)
for interface in config:
for interface_config in config:
interface = interface_config.keys()[0]
if interface in _stats:
_if_stats = _stats[interface]
_diff = False
for attr in __attrs:
if attr in config[interface]:
if 'type' in config[interface] and config[interface]['type'] == 'equal':
if _if_stats.__dict__[attr] == int(config[interface][attr]):
if attr in interface_config[interface]:
if 'type' in interface_config[interface] and \
interface_config[interface]['type'] == 'equal':
if getattr(_if_stats, attr, None) == \
int(interface_config[interface][attr]):
_diff = True
elif 'type' in config[interface] and config[interface]['type'] == 'greater':
if _if_stats.__dict__[attr] > int(config[interface][attr]):
elif 'type' in interface_config[interface] and \
interface_config[interface]['type'] == 'greater':
if getattr(_if_stats, attr, None) > \
int(interface_config[interface][attr]):
_diff = True
else:
log.debug('attr {}'.format(getattr(_if_stats,
attr, None)))
else:
if _if_stats.__dict__[attr] == int(config[interface][attr]):
if getattr(_if_stats, attr, None) == \
int(interface_config[interface][attr]):
_diff = True
if _diff:
ret.append({'interface': interface,