check_bandwidth: fix table and adjust layout
This commit is contained in:
parent
0ddcbdc382
commit
f820bbf131
|
@ -29,6 +29,12 @@ else:
|
||||||
ignore_re = None
|
ignore_re = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_interface_data(interface: str, data: list):
|
||||||
|
for y in data:
|
||||||
|
if y[0] == interface:
|
||||||
|
return y
|
||||||
|
|
||||||
|
|
||||||
def get_network_traffic(interface):
|
def get_network_traffic(interface):
|
||||||
net_io = psutil.net_io_counters(pernic=True)
|
net_io = psutil.net_io_counters(pernic=True)
|
||||||
if interface in net_io:
|
if interface in net_io:
|
||||||
|
@ -99,21 +105,30 @@ def main():
|
||||||
else:
|
else:
|
||||||
ok.append(interface)
|
ok.append(interface)
|
||||||
state = 'ok'
|
state = 'ok'
|
||||||
data[i][2] = f'[{state.upper()}]'
|
data[i][4] = f'[{state.upper()}]'
|
||||||
perf_data.append(f'{interface}={round(bandwidth_utilization, 2)}Mbps;{warn_value};{crit_value};{f"0;{args.max};" if args.max else ""} ')
|
perf_data.append(f'{interface}={round(bandwidth_utilization, 2)}Mbps;{warn_value};{crit_value};{f"0;{args.max};" if args.max else ""} ')
|
||||||
|
|
||||||
if len(ok):
|
# Print the status
|
||||||
print(f'OK: {", ".join(ok)}')
|
if exit_code == nagios.CRITICAL:
|
||||||
if len(warn):
|
status = 'CRITICAL'
|
||||||
print(f'WARNING: {", ".join(warn)}')
|
listed_interfaces = [*critical, *warn]
|
||||||
if len(critical):
|
elif exit_code == nagios.WARNING:
|
||||||
print(f'CRITICAL: {", ".join(critical)}')
|
status = 'WARNING'
|
||||||
|
listed_interfaces = warn
|
||||||
|
else:
|
||||||
|
status = 'OK'
|
||||||
|
listed_interfaces = ok
|
||||||
|
|
||||||
data = [(x[0], f'{round(x[1], 2)} Mbps', x[2]) for x in data]
|
listed_glances = []
|
||||||
|
for interface in listed_interfaces:
|
||||||
|
listed_glances.append(f'{interface}: {round(get_interface_data(interface, data)[3], 2)}Mbps')
|
||||||
|
print(f'{status} - {", ".join(listed_glances)}')
|
||||||
|
|
||||||
|
data = [(x[0], f'{round(x[3], 2)} Mbps', x[4]) for x in data]
|
||||||
data.insert(0, ('Interface', 'Bandwidth', 'State'))
|
data.insert(0, ('Interface', 'Bandwidth', 'State'))
|
||||||
print(list_to_markdown_table(data, align='left', seperator='!', borders=False))
|
print(list_to_markdown_table(data, align='left', seperator='!', borders=False))
|
||||||
|
|
||||||
print(f' |{"".join(perf_data)}')
|
print(f'|{"".join(perf_data)}')
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue