Repository navigation
feat(udm-wan-monitor): support UniFi Cloud Gateways (UCG), rename to UniFi WAN-Monitor, fix polling on current DOCSight - #14
Conversation
…UniFi WAN-Monitor, fix polling on current DOCSight Verified against a UCG Ultra (UDRULT, UniFi OS 5.1.33), including a real failover (WAN 1 unplugged and reconnected). - Derive WAN port names from the gateway's wan1/wan2 ifname instead of hardcoding the UDM Pro's eth9/eth8 (UCG Ultra: eth4/eth0), so it follows whichever ports are assigned as WAN, including reassigned LAN ports. Only wan1 and wan2 are considered; a WAN that is not configured produces no row. Dashboard cards show the real ifname. - Select the gateway by type (udm/ugw/usg/ucg) and presence of wan1; never fall back to devices[0], which could be a switch or AP and would report a bogus offline WAN. Fail with "No gateway device found" or "No WAN interface (wan1/wan2) found on gateway" instead. - Fix CollectorResult.ok()/failure() no longer existing in current DOCSight (every poll was recorded as a failure). Helpers use them only if present. - Reuse the collector's session for dashboard requests and only fall back to the legacy /api/login on 404/405. A login per request tripped UniFi OS' login rate limit (429), which was then masked as a 401. - Rename the module to "UniFi WAN-Monitor" (display name only; module id, directory, routes and event type are unchanged) and mention UCG in the texts. - Version 3.2.0.
|
Thanks for pinging @Oggy512, @itsDNNS! Oggy512's last GitHub activity was in late July, so I wanted to ask: @sparkleHazard, you worked on this module in #11 — if you have a UDM Pro/SE, could you give this a quick test instead? Checking that the WAN cards and the port table still show WAN 1 / WAN 2 as before would be enough. It should behave the same: UDM and UCG run the same UniFi OS / Network application, and the WAN port names are now read from the gateway's own @itsDNNS if nobody can test, how long would you like to wait before deciding how to proceed with this and #15/#16? |
|
I'm currently traveling and can't test/review it directly. |
|
Thanks, Lennard, and thanks @Oggy512 for the update. Let’s give Oggy the two weeks he mentioned, so until October 28. If someone can verify the UDM behaviour sooner and the review looks good, we can merge earlier, in order: #14, #15, then #16. If no UDM test is available by then, I’ll review where we stand and decide how to proceed rather than leave these waiting indefinitely. Your UCG testing is helpful; the main remaining question is compatibility with existing UDM setups. |
Hi @Oggy512, thanks for the module! I use a UCG Ultra and extended it so it works for UCG users as well. Since I can only test on my own hardware, it would be great if you (or anyone with a UDM Pro/SE) could check that UDMs still work as before.
Summary
The UDM WAN Monitor only worked on UDM Pro/SE: the WAN port names were hardcoded, and on current DOCSight versions the collector failed on every poll. This PR makes the module work on UniFi Cloud Gateways (UCG) too and fixes the problems I ran into on the way. Verified live against a UCG Ultra (model
UDRULT, UniFi OS 5.1.33).Changes
wan1/wan2ifnameinstead of hardcodedeth9/eth8, so it follows whichever ports are assigned as WAN, including reassigned LAN ports (my UCG Ultra uses the dedicated WAN porteth4as WAN 1 and the LAN porteth0as WAN 2). Onlywan1andwan2are considered; a WAN that is not configured produces no port row. The WAN cards show the real interface name. Additional ports can still be added via the existing extra-port settings.udm/ugw/usg/ucg) and presence ofwan1. The previous fallback todevices[0]could select a switch or access point, which has no WAN data and would be reported as an offline WAN (and produce false critical events). The module now fails with "No gateway device found", or "No WAN interface (wan1/wan2) found on gateway" if the gateway reports neither WAN.CollectorResult.ok()/.failure()do not exist in current DOCSight (it is a plain dataclass), so every poll raisedAttributeErrorand was counted as a failure with backoff. The helpers are now only used if present, otherwise the dataclass is built directly./api/loginthen turned that into a misleading 401. Dashboard requests now reuse the collector's session, and the legacy endpoint is only tried on 404/405. The connection test still performs a fresh login so it checks the entered credentials..settings-cardno longer pads itself), so the fields touched the card border. It now uses DOCSight's--card-padding(with a fallback for older versions).community.udm_wan_monitor, directory, routes (/udm-wan,/api/udm-wan/*) and event type are intentionally unchanged, so existing installs, settings, bookmarks and stored events keep working. DOCSight derives the dashboard tab's URL fragment from the module id, so it still reads#mod-community-udm_wan_monitor; changing that would need a new module id, which I did not want to impose here. Happy to revert the rename if you prefer to keep the old name.Testing
python3 -m unittest discover -s testsandscripts/validate_registry.pypass.link DOWN,offlineandWAN failover: WAN 1 → WAN 2events within about a minute; plugging it back producedlink UP,back onlineand the failover back to WAN 1, with no spurious events in between.