Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: get Freifunk SSID Client count #1

Merged
merged 5 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions omada/omada.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,9 @@ def getSites(self):
def getSiteDevices(self, site=None):
return self.__get(f"/sites/{self.__findKey(site)}/devices")

##
## Get the Details of an AP
##

##
## Get the Details of an AP
##
def getSiteAP(self, site=None, mac=None):
return self.__get(f"/sites/{self.__findKey(site)}/eaps/{mac}")

Expand All @@ -474,6 +473,15 @@ def getSiteClients(self, site=None):
f"/sites/{self.__findKey(site)}/clients", params={"filters.active": "true"}
)

##
## Returns the list of active clients for given site and AP.
##
def getSiteClientsAP(self, site=None, apmac=None):
return self.__geterator(
f"/sites/{self.__findKey(site)}/clients",
params={"filters.active": "true", "filters.apMac": apmac},
)

##
## Returns the list of alerts for given site.
##
Expand Down
89 changes: 51 additions & 38 deletions omada_respondd/omada_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,31 @@ class Accesspoints:
accesspoints: List[Accesspoint]


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."""
def get_client_count_for_ap(clients, cfg):
"""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


def get_traffic_count_for_ap(clients, cfg):
"""This function returns the number total clients, 2,4Ghz clients and 5Ghz clients connected to an AP with Freifunk SSID."""
tx = 0
rx = 0
for client in clients:
if re.search(cfg.ssid_regex, client.get("ssid", "")):
tx += client.get("trafficUp", 0)
rx += client.get("trafficDown", 0)

return tx, rx


def get_location_by_address(address, app):
"""This function returns latitude and longitude of a given address."""
time.sleep(1)
Expand Down Expand Up @@ -143,24 +154,42 @@ 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("status", 0) != 0 and ap.get("status", 0) != 20)
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)

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(
clients=csite.getSiteClientsAP(apmac=ap_mac), cfg=cfg
)

# Traffic from entire AP (TODO: Filter Freifunk for ?SSID?)
# (
# tx2,
# rx2,
# ) = get_traffic_count_for_ap(clients=csite.getSiteClientsAP(apmac=ap_mac), cfg=cfg)

tx = 0
rx = 0

radioTraffic2g = moreAPInfos.get("radioTraffic2g", None)
if radioTraffic2g is not None:
tx = tx + radioTraffic2g.get("tx", 0)
Expand All @@ -171,25 +200,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 +211,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 +260,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
Loading