Skip to content

Commit

Permalink
some cleanup and add option to get only Freifunk Client Count
Browse files Browse the repository at this point in the history
  • Loading branch information
T0biii committed May 19, 2024
1 parent 2a73912 commit b851e00
Showing 1 changed file with 33 additions and 36 deletions.
69 changes: 33 additions & 36 deletions omada_respondd/omada_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b851e00

Please sign in to comment.