Fix crash on first agent execution due to no deltas available

This commit is contained in:
Albert Stefanov 2023-10-30 07:41:22 +02:00
parent 041b05d0e5
commit c0bf10bc89
3 changed files with 12 additions and 10 deletions

View File

@ -2,10 +2,13 @@
from .agent_based_api.v1 import * from .agent_based_api.v1 import *
def check_wifi_status(item, section): def __try_parse_int(val: str, default: int) -> int:
print(item) try:
print(section) return int(val)
except ValueError:
return default
def check_wifi_status(item, section):
for interface in section: for interface in section:
if interface['name'] == item: if interface['name'] == item:
usage = interface['delta_ch_time_busy'] / interface['delta_ch_time'] * 100 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}%") yield Result(state = State.CRIT, summary = f"Clients: {interface['client_count']}, Channel usage: {usage:.02f}%")
def discover_wifi_status(section): def discover_wifi_status(section):
print(section)
for interface in section: for interface in section:
yield Service(item=interface['name']) yield Service(item=interface['name'])
@ -34,8 +36,8 @@ def parse_wifi_interfaces(string_table):
'ch_time' : int(row[1]), 'ch_time' : int(row[1]),
'ch_time_busy' : int(row[2]), 'ch_time_busy' : int(row[2]),
'noise' : int(row[3]), 'noise' : int(row[3]),
'delta_ch_time' : int(row[4]), 'delta_ch_time' : __try_parse_int(row[4], 1),
'delta_ch_time_busy' : int(row[5]), 'delta_ch_time_busy' : __try_parse_int(row[5], 0),
'client_count' : int(row[6]), 'client_count' : int(row[6]),
} for row in string_table] } for row in string_table]

View File

@ -7,7 +7,7 @@ mkp.dist({'author': 'Albert Stefanov <aastefanov@outlook.com>',
'name': 'wifi_interfaces', 'name': 'wifi_interfaces',
'title': 'OpenWRT Wi-Fi Interfaces', 'title': 'OpenWRT Wi-Fi Interfaces',
'download_url': 'https://github.com/openfest/openfest-network-2023', 'download_url': 'https://github.com/openfest/openfest-network-2023',
'version': '0.0.2', 'version': '0.0.3',
'version.min_required': '2.0.0', 'version.min_required': '2.0.0',
}, },
path='.') path='.')

View File

@ -69,7 +69,7 @@ graph_info["noise_floor"] = {
graph_info["channel_times"] = { graph_info["channel_times"] = {
"title": _("Channel Times"), "title": _("Channel Times"),
"metrics": [ "metrics": [
("delta_ch_time", "stack"), ("delta_ch_time", "line"),
("delta_ch_time_busy", "stack") ("delta_ch_time_busy", "area")
], ],
} }