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

gateway from list #23

Merged
merged 1 commit into from
Jan 12, 2022
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ controller_port: 8443
username: ubnt
password: ubnt
ssid_regex: .*freifunk.*
offloader_mac:
SiteName: 00:00:00:00:00:00
SiteName2: 00:00:00:00:00:00
nodelist: https://MAPURL/data/meshviewer.json
version: v5
ssl_verify: True
multicast_enabled: false
Expand Down
1 change: 1 addition & 0 deletions unifi_respondd.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ssid_regex: .*freifunk.*
offloader_mac:
SiteName: 00:00:00:00:00:00
SiteName2: 00:00:00:00:00:00
nodelist: https://MAPURL/data/meshviewer.json
version: v5
ssl_verify: True
multicast_enabled: false
Expand Down
2 changes: 2 additions & 0 deletions unifi_respondd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Config:
password: str
ssid_regex: str
offloader_mac: Dict[str, str]
nodelist: str

multicast_address: str
multicast_port: int
Expand Down Expand Up @@ -62,6 +63,7 @@ def from_dict(cls, cfg: Dict[str, str]) -> "Config":
password=cfg["password"],
ssid_regex=cfg["ssid_regex"],
offloader_mac=cfg["offloader_mac"],
nodelist=cfg["nodelist"],
version=cfg["version"],
ssl_verify=cfg["ssl_verify"],
multicast_enabled=cfg["multicast_enabled"],
Expand Down
20 changes: 16 additions & 4 deletions unifi_respondd/unifi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from typing import List
from geopy.geocoders import Nominatim
from unifi_respondd import config
from requests import get as rget
import time
import dataclasses
import re

ffnodes = None

@dataclasses.dataclass
class Accesspoint:
Expand Down Expand Up @@ -93,10 +95,17 @@ def get_location_by_address(address, app):
except:
return get_location_by_address(address)

def scrape(url):
"""returns remote json"""
try:
return rget(url).json()
except Exception as ex:
print('Error: %s' %(ex))

def get_infos():
"""This function gathers all the information and returns a list of Accesspoint objects."""
cfg = config.Config.from_dict(config.load_config())
ffnodes = scrape(cfg.nodelist)
c = Controller(
host=cfg.controller_url,
username=cfg.username,
Expand Down Expand Up @@ -153,7 +162,10 @@ def get_infos():
except:
pass
neighbour_mac = cfg.offloader_mac.get(site["desc"], None)
offloader_mac = cfg.offloader_mac.get(site["desc"], "").replace(':', '')
offloader_id = cfg.offloader_mac.get(site["desc"], "").replace(':', '')
offloader = list(filter(lambda x:x["mac"]==cfg.offloader_mac.get(site["desc"], ""),ffnodes["nodes"]))[0]
gateway = offloader["gateway"]
gateway6 = offloader["gateway6"]
uplink = ap.get("uplink", None)
if uplink is not None and uplink.get("ap_mac", None) is not None:
neighbour_mac = uplink.get("ap_mac")
Expand All @@ -179,9 +191,9 @@ def get_infos():
mem_total=ap.get("sys_stats", {}).get("mem_total", 0),
tx_bytes=tx,
rx_bytes=rx,
gateway=offloader_mac,
gateway6=offloader_mac,
gateway_nexthop=offloader_mac,
gateway=gateway,
gateway6=gateway6,
gateway_nexthop=offloader_id,
neighbour_mac=neighbour_mac,
)
)
Expand Down