Fix crash on first agent execution due to no deltas available
This commit is contained in:
parent
041b05d0e5
commit
c0bf10bc89
|
@ -2,10 +2,13 @@
|
|||
|
||||
from .agent_based_api.v1 import *
|
||||
|
||||
def check_wifi_status(item, section):
|
||||
print(item)
|
||||
print(section)
|
||||
def __try_parse_int(val: str, default: int) -> int:
|
||||
try:
|
||||
return int(val)
|
||||
except ValueError:
|
||||
return default
|
||||
|
||||
def check_wifi_status(item, section):
|
||||
for interface in section:
|
||||
if interface['name'] == item:
|
||||
usage = interface['delta_ch_time_busy'] / interface['delta_ch_time'] * 100
|
||||
|
@ -23,7 +26,6 @@ def check_wifi_status(item, section):
|
|||
yield Result(state = State.CRIT, summary = f"Clients: {interface['client_count']}, Channel usage: {usage:.02f}%")
|
||||
|
||||
def discover_wifi_status(section):
|
||||
print(section)
|
||||
for interface in section:
|
||||
yield Service(item=interface['name'])
|
||||
|
||||
|
@ -34,8 +36,8 @@ def parse_wifi_interfaces(string_table):
|
|||
'ch_time' : int(row[1]),
|
||||
'ch_time_busy' : int(row[2]),
|
||||
'noise' : int(row[3]),
|
||||
'delta_ch_time' : int(row[4]),
|
||||
'delta_ch_time_busy' : int(row[5]),
|
||||
'delta_ch_time' : __try_parse_int(row[4], 1),
|
||||
'delta_ch_time_busy' : __try_parse_int(row[5], 0),
|
||||
'client_count' : int(row[6]),
|
||||
} for row in string_table]
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ mkp.dist({'author': 'Albert Stefanov <aastefanov@outlook.com>',
|
|||
'name': 'wifi_interfaces',
|
||||
'title': 'OpenWRT Wi-Fi Interfaces',
|
||||
'download_url': 'https://github.com/openfest/openfest-network-2023',
|
||||
'version': '0.0.2',
|
||||
'version': '0.0.3',
|
||||
'version.min_required': '2.0.0',
|
||||
},
|
||||
path='.')
|
||||
|
|
|
@ -69,7 +69,7 @@ graph_info["noise_floor"] = {
|
|||
graph_info["channel_times"] = {
|
||||
"title": _("Channel Times"),
|
||||
"metrics": [
|
||||
("delta_ch_time", "stack"),
|
||||
("delta_ch_time_busy", "stack")
|
||||
("delta_ch_time", "line"),
|
||||
("delta_ch_time_busy", "area")
|
||||
],
|
||||
}
|
Loading…
Reference in New Issue