From b851e0076df0b17f3b7cdd1e306806eb09d53c50 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 20 May 2024 00:49:08 +0200 Subject: [PATCH] some cleanup and add option to get only Freifunk Client Count --- omada_respondd/omada_client.py | 69 ++++++++++++++++------------------ 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/omada_respondd/omada_client.py b/omada_respondd/omada_client.py index ec89a81..fcaea9e 100644 --- a/omada_respondd/omada_client.py +++ b/omada_respondd/omada_client.py @@ -76,16 +76,15 @@ class Accesspoints: def get_client_count_for_ap(ap_mac, clients, cfg): - """This function returns the number total clients, 2,4Ghz clients and 5Ghz clients connected to an AP.""" + """This function returns the number total clients, 2,4Ghz clients and 5Ghz clients connected to an AP with Freifunk SSID.""" client5_count = 0 client24_count = 0 for client in clients: - if re.search(cfg.ssid_regex, client.get("essid", "")): - if client.get("ap_mac", "No mac") == ap_mac: - if client.get("channel", 0) > 14: - client5_count += 1 - else: - client24_count += 1 + if re.search(cfg.ssid_regex, client.get("ssid", "")): + if client.get("channel", 0) > 14: + client5_count += 1 + else: + client24_count += 1 return client24_count + client5_count, client24_count, client5_count @@ -143,24 +142,38 @@ def get_infos(): autoupgrade = siteSettings["autoUpgrade"]["enable"] aps_for_site = csite.getSiteDevices() - clients = csite.getSiteClients() for ap in aps_for_site: if ( ap.get("name", None) is not None and ( ap.get("status", 0) != 0 and ap.get("status", 0) != 20 - ) ##Offline Check + ) and ap.get("type") == "ap" ): - moreAPInfos = csite.getSiteAP(mac=ap["mac"]) - - # ssids = ap.get("vap_table", None) - - # containsSSID = False - + ap_mac = ap["mac"] + moreAPInfos = csite.getSiteAP(mac=ap_mac) + clientsAP = csite.getSiteClientsAP(apmac=ap_mac) + + ssids = moreAPInfos.get("ssidOverrides", None) + containsSSID = False + if ssids is not None: + for ssid in ssids: + if re.search(cfg.ssid_regex, ssid.get("ssid", "")): + if(ssid.get("ssidEnabled"), False): + containsSSID = True + + if containsSSID is False: + continue # Skip AP if Freifunk SSID is missing + + ( + client_count, + client_count24, + client_count5, + ) = get_client_count_for_ap(ap_mac, clientsAP, cfg) + + #Traffic from entire AP (TODO: Filter Freifunk for ?SSID?) tx = 0 rx = 0 - radioTraffic2g = moreAPInfos.get("radioTraffic2g", None) if radioTraffic2g is not None: tx = tx + radioTraffic2g.get("tx", 0) @@ -171,25 +184,8 @@ def get_infos(): tx = tx + radioTraffic5g.get("tx", 0) rx = rx + radioTraffic5g.get("rx", 0) - client_count = ap.get("clientNum") - client_count24 = ap.get("clientNum2g") - client_count5 = ap.get("clientNum5g") - # if ssids is not None: - # for ssid in ssids: - # if re.search(cfg.ssid_regex, ssid.get("essid", "")): - # containsSSID = True - # tx = tx + ssid.get("tx_bytes", 0) - # rx = rx + ssid.get("rx_bytes", 0) - # if containsSSID: - # ( - # client_count, - # client_count24, - # client_count5, - # ) = get_client_count_for_ap(ap.get("mac", None), clients, cfg) - neighbour_macs = [] - - moreAPInfos.get("cpuUtil") # in Prozent - moreAPInfos.get("memUtil") # in Prozent + moreAPInfos.get("cpuUtil") #TODO: cpuUtil in Prozent + moreAPInfos.get("memUtil") #TODO: memUtil in Prozent wp2g = moreAPInfos.get("wp2g", None) if wp2g.get("actualChannel", None) is not None: @@ -199,6 +195,7 @@ def get_infos(): if wp5g.get("actualChannel", None) is not None: frequency5 = get_ap_frequency(wp5g.get("actualChannel")) + neighbour_macs = [] try: neighbour_macs.append(cfg.offloader_mac.get(site["name"], None)) offloader_id = cfg.offloader_mac.get(site["name"], "").replace( @@ -247,7 +244,7 @@ def get_infos(): aps.accesspoints.append( Accesspoint( name=ap.get("name", None), - mac=ap.get("mac", None).replace("-", ":").lower(), + mac=ap_mac.replace("-", ":").lower(), snmp_location=snmp.get("location", None), client_count=client_count, client_count24=client_count24,