Skip to content

feat(udm-wan-monitor): support UniFi Cloud Gateways (UCG), rename to UniFi WAN-Monitor, fix polling on current DOCSight - #14

Open
lennard0711 wants to merge 1 commit into
itsDNNS:mainfrom
lennard0711:feat/udm-wan-ucg-compat
Open

lennard0711 wants to merge 1 commit into
itsDNNS:mainfrom
lennard0711:feat/udm-wan-ucg-compat

Conversation

@lennard0711

Copy link
Copy Markdown

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

  • WAN ports: derived from the gateway's own wan1/wan2 ifname instead of hardcoded eth9/eth8, so it follows whichever ports are assigned as WAN, including reassigned LAN ports (my UCG Ultra uses the dedicated WAN port eth4 as WAN 1 and the LAN port eth0 as WAN 2). Only wan1 and wan2 are 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.
  • Gateway selection: pick the device by type (udm/ugw/usg/ucg) and presence of wan1. The previous fallback to devices[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.
  • Collector result: CollectorResult.ok() / .failure() do not exist in current DOCSight (it is a plain dataclass), so every poll raised AttributeError and was counted as a failure with backoff. The helpers are now only used if present, otherwise the dataclass is built directly.
  • Login rate limit: the dashboard logged in again on every request, on top of the collector. On my UCG this quickly triggered UniFi OS' login rate limit (HTTP 429); the fallback to the legacy /api/login then 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 layout: the settings card had no inner padding on current DOCSight versions (.settings-card no longer pads itself), so the fields touched the card border. It now uses DOCSight's --card-padding (with a fallback for older versions).
  • Rename: the module is now called "UniFi WAN-Monitor" since it supports more than the UDM line. Only the display name changes (manifest, registry, README, UI strings in en/de/fr/es, page titles). The module id 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.
  • Texts mention UCG alongside UDM; version 3.1.4 → 3.2.0.

Testing

  • python3 -m unittest discover -s tests and scripts/validate_registry.py pass.
  • Run in a DOCSight container against a real UCG Ultra: login, collector polling, WAN status and port table work, no errors in the log; repeated dashboard refreshes no longer trigger additional logins.
  • Failover tested live: unplugging the WAN 1 cable produced link DOWN, offline and WAN failover: WAN 1 → WAN 2 events within about a minute; plugging it back produced link UP, back online and the failover back to WAN 1, with no spurious events in between.
  • Not tested on real hardware: UDM Pro/SE, UCG Max/Fiber. UDM behaviour is unchanged by design (same type handling and WAN interface names taken from the device), but please verify on a UDM if you can.

…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.
@itsDNNS

itsDNNS commented Oct 10, 2026

Copy link
Copy Markdown
Owner

@Oggy512 please review this when you get a chance. I don't have any UniFi hardware, so I can't verify these changes myself, in particular that UDM Pro/SE setups keep working as before. The same goes for the follow-ups #15 and #16.

@lennard0711

Copy link
Copy Markdown
Author

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 wan1/wan2 data instead of being hardcoded. I could only verify it on a UCG Ultra, though.

@itsDNNS if nobody can test, how long would you like to wait before deciding how to proceed with this and #15/#16?

@Oggy512

Oggy512 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

I'm currently traveling and can't test/review it directly.
I'll look into it in the next 2 weeks, if no one else can verify in the meantime.

@itsDNNS

itsDNNS commented Oct 16, 2026

Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants