Skip to content

feat(udm-wan-monitor): define WAN ports manually and choose the cable WAN - #16

Draft
lennard0711 wants to merge 3 commits into
itsDNNS:mainfrom
lennard0711:feat/udm-wan-manual-wan-ports
Draft

lennard0711 wants to merge 3 commits into
itsDNNS:mainfrom
lennard0711:feat/udm-wan-manual-wan-ports

Conversation

@lennard0711

Copy link
Copy Markdown

Builds on the UCG support PR (#14, 3.2.0) and the display PR (3.2.1) and bumps the module to 3.3.0. Please merge those first; until then this PR also shows their commits.

Hi @Oggy512, this replaces the four fixed "extra port" fields with a list you can add to, lets users define WAN ports by hand when the gateway reports none, and adds a setting for which WAN carries the cable connection DOCSight monitors.

Summary

Port assignment is flexible on UniFi gateways (on my UCG Ultra a LAN port is WAN 2). If automatic detection finds no wan1/wan2, the user can now define the WAN port(s) themselves instead of being stuck. With two WANs, users can also mark which one is the cable connection.

Changes

  • Manual WAN ports: the four fixed fields are replaced by a list with an "Add port" button (dialog for interface + alias, remove button per row, up to 8 ports). Stored as JSON in the new key udm_wan_extra_ports. The dialog uses DOCSight's own modal classes and sits outside the settings form so its inputs are not saved as stray config keys. Entries are validated (interface name pattern, no duplicates, alias ≤ 40 chars).
  • Backwards compatible: while udm_wan_extra_ports has never been saved, the legacy udm_wan_extra_port{1,2}_* fields are read and shown in the list. After the first save the list takes over.
  • No WAN found: the module no longer fails if ports were defined manually; they show up in the port table (link, speed, traffic). Without manual ports it still fails, and the error now points to the setting. A WAN that is not configured is shown as unknown instead of offline.
  • Cable WAN: new setting "Cable connection (relevant for DOCSight)" (not set / WAN 1 / WAN 2) for the WAN that carries the cable/DOCSIS connection. The selected WAN gets a "DOCSight" badge and is shown first in the dashboard. With a cable WAN set, outages of the other WAN (link down, offline, not alive) are reported as warning instead of critical, since the monitored connection is still up; the cable WAN keeps critical. Not set (default) = unchanged behaviour. Failover events are unchanged.
  • Translations (en/de/fr/es) updated; version 3.2.1 → 3.3.0.

Note: UniFi only reports alive/online status for wan1/wan2, so manually defined ports are display-only (as the old extra ports were).

Testing

  • python3 -m unittest discover -s tests and scripts/validate_registry.py pass.
  • Tried in the DOCSight settings UI against a UCG Ultra: adding, duplicate and invalid input, removing, saving, and the resulting rows in the dashboard port table; the cable WAN selection saves and the badge/ordering show up in the dashboard.
  • The event severity rule was checked with simulated state transitions (other WAN down → warning, cable WAN down → critical, not set → unchanged), not with a second real failover.
  • The "gateway reports no WAN" path was checked with simulated device data only, not on real hardware. Not tested on a UDM.

…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.
- IP: show the WAN interface's own address, as UniFi Network does. Behind
  another router (double NAT) that is a private address, so the previous
  geo-detected public address looked wrong next to the UniFi dashboard.
  The public address stays available as ip_public and is shown in an extra
  "Public IP" row only when it differs from the interface IP.
- IPv6: skip link-local (fe80::/10) addresses. UniFi lists them first, so an
  uplink without IPv6 showed a link-local address as if it had one.
- Add label_ip_public translations (en, de, fr, es).
… WAN

Manual WAN ports
When the gateway reports no wan1/wan2 (or another port should be monitored,
e.g. an SFP+ uplink), WAN ports can now be added by interface name.

- Settings: replace the four fixed "extra port" fields with a list and an
  "Add port" button (dialog for interface + alias, remove button per row, up
  to 8 ports). The list is stored as JSON in the new key udm_wan_extra_ports.
  The dialog lives outside the settings form, so its fields are not saved as
  stray config keys.
- Existing setups keep working: while udm_wan_extra_ports has never been
  saved, the legacy udm_wan_extra_port{1,2}_* fields are read and shown in
  the list; after the first save the list takes over.
- The module no longer fails with "No WAN interface" when ports were defined
  manually; they are shown in the port table (link, speed, traffic). A WAN
  without interface is shown as unknown instead of offline on the dashboard.
- Entries are validated (interface name pattern, no duplicates, alias max 40
  chars, max 8 ports).

Cable WAN
New setting udm_wan_primary (not set / WAN 1 / WAN 2) for the WAN that
carries the cable connection DOCSight monitors.

- Dashboard: the selected WAN gets a "DOCSight" badge and is shown first.
- Events: with a cable WAN set, outages of the other WAN (link down, offline,
  not alive) are reported as warning instead of critical; the cable WAN keeps
  critical. Not set = unchanged behaviour.

Version 3.3.0.
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.

1 participant