From 33058289475c57e48ee7a634722bf6dd391728e7 Mon Sep 17 00:00:00 2001 From: ffsb Date: Sat, 20 Jul 2024 13:26:49 -0400 Subject: [PATCH 1/2] 1.1 handle failed omada devices calls. --- front/plugins/omada_sdn_imp/testre.py | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/front/plugins/omada_sdn_imp/testre.py b/front/plugins/omada_sdn_imp/testre.py index 544e7858..4e382fe7 100644 --- a/front/plugins/omada_sdn_imp/testre.py +++ b/front/plugins/omada_sdn_imp/testre.py @@ -192,4 +192,47 @@ def testparalel(): print(f"arg:{arg}, result={results[arg]}, result2={results2[arg]}") -testparalel() \ No newline at end of file +#testparalel() + + + +import netifaces +import ipaddress + +def get_interfaces_and_subnets(): + result = [] + for interface in netifaces.interfaces(): + addrs = netifaces.ifaddresses(interface) + if netifaces.AF_INET in addrs: + for addr in addrs[netifaces.AF_INET]: + ip = addr['addr'] + mask = addr['netmask'] + try: + network = ipaddress.IPv4Network(f"{ip}/{mask}", strict=False) + result.append((interface, str(network))) + except ValueError: + pass + return result + +# Example usage: +interfaces_and_subnets = get_interfaces_and_subnets() +for interface, subnet in interfaces_and_subnets: + print(f"interface={interface}, subnet={subnet}") + + +''' +interface=lo, subnet=127.0.0.0/8 +interface=enp6s0, subnet=192.168.0.0/24 +interface=br-ba0070d71f2a, subnet=172.16.0.16/29 +interface=br-bc4a4c4e0f93, subnet=172.16.0.40/29 +interface=br-e043e0ae9c8c, subnet=172.16.0.72/29 +interface=br-6acc3945cfba, subnet=172.16.0.48/29 +interface=br-6f931807e709, subnet=172.16.0.80/29 +interface=docker0, subnet=172.17.0.0/16 +interface=br-9ce2cb7c38c3, subnet=172.16.0.24/29 +interface=br-eec81501f666, subnet=172.16.0.32/29 +interface=br-1064712a4791, subnet=172.16.0.56/29 +interface=br-a93ebdba2a28, subnet=172.16.0.8/29 +interface=br-d8fa7a3015e2, subnet=172.16.0.64/29 +interface=br-e7cdd041d3d3, subnet=172.16.0.0/29 +''' \ No newline at end of file From 43759b6b7d5fd716a242a939ef15810a671fdd4d Mon Sep 17 00:00:00 2001 From: ffsb Date: Sat, 20 Jul 2024 13:28:43 -0400 Subject: [PATCH 2/2] na --- front/plugins/omada_sdn_imp/omada_sdn.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/front/plugins/omada_sdn_imp/omada_sdn.py b/front/plugins/omada_sdn_imp/omada_sdn.py index 5395a6dc..5e9bfe9f 100755 --- a/front/plugins/omada_sdn_imp/omada_sdn.py +++ b/front/plugins/omada_sdn_imp/omada_sdn.py @@ -6,6 +6,8 @@ __version__ = "0.3" # split devices API calls to allow multithreading but had t __version__ = "0.6" # found issue with multithreading - my omada calls redirect stdout which gets clubbered by normal stdout... not sure how to fix for now... __version__ = "0.7" # avoid updating omada sdn client name when it is the MAC, and naxname is also the same MAC... __version__ = "1.0" # fixed the timzone mylog issue by resetting the tz value at the begining of the script... I suspect it doesn't inherit the tz from the main. +__version__ = "1.1" # added logic to handle gracefully a failure of omada devices so it won't try to populate uplinks on non-existent switches and AP. + # query OMADA SDN to populate NetAlertX witch omada switches, access points, clients. # try to identify and populate their connections by switch/accesspoints and ports/SSID @@ -454,7 +456,8 @@ def get_device_data(omada_clients_output,switches_and_aps,device_handler): # step4, let's go recursively through switches other links to mark update their uplinks # and pray it ends one day... # - add_uplink(default_router_mac,first_switch, device_data_bymac,sadevices_linksbymac,port_byswitchmac_byclientmac) + if len(sadevices) > 0: + add_uplink(default_router_mac,first_switch, device_data_bymac,sadevices_linksbymac,port_byswitchmac_byclientmac) return device_data_bymac.values() if __name__ == '__main__':