Skip to content

feat: add WAN status inventory - #8

Merged
rvben merged 1 commit into
rvben:mainfrom
Kampe:agent/wan-status
Aug 18, 2026
Merged

rvben merged 1 commit into
rvben:mainfrom
Kampe:agent/wan-status

Conversation

@Kampe

@Kampe Kampe commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What

Add read-only unifi wan list with link, health, traffic, and cellular modem telemetry for WAN1-WAN3.

Why

Multi-WAN and cellular failover state currently require controller UI inspection. This exposes the underlying state without flattening Ethernet and mobile-backup semantics into one misleading status flag.

Safety

The gateway response is decoded into narrow typed records. Modem identifiers and unknown vendor fields are omitted; regression fixtures inject secret-like fields and verify they never reach output.

Checks

  • env -u UNIFI_API_KEY -u UNIFI_HOST make check
  • Live read-only validation against a three-interface UniFi gateway with a ready cellular backup

@rvben

rvben commented Aug 14, 2026

Copy link
Copy Markdown
Owner

This is useful and I would like to take it. Two things first.

Negative sentinels published as measurements. latency and availability are Option<f64>, so a -1 from the controller deserializes cleanly and is emitted as latency_ms: -1.0. A caller cannot distinguish that from a real reading. UniFi does use -1 as an unmeasured marker in this family of fields: in a single stat/device response from my controller it appears in icmp_avg_rtt, dns_avg_latency, satisfaction, min_rssi and uplink_table[].signal. My WAN is up so I could not capture a down-link wan1 block directly, but null rather than -1.0 is the honest value there and the mapping is cheap to add.

Numeric width, lower confidence. speed, rx_bytes, tx_bytes, rx_rate and tx_rate are Option<u64>, and a single negative value anywhere in the WAN block fails the whole deserialization rather than degrading one field:

invalid value: integer `-1`, expected u64

I want to be straight that I could not evidence the trigger. I assumed at first that speed used the same -1 marker, but on my hardware down switch ports report speed: 0, and no field with "speed" in its path holds -1 anywhere in the payload. So this may never fire in practice. It is worth hardening because the failure mode is total rather than local, but treat it as defensive rather than as a reported bug.

Gateway match. matches!(device_type, Some("ugw" | "udm")) works on my UCG-Ultra, which reports udm. My understanding is that UXG hardware reports uxg and would fall through to "UniFi gateway not found", but I do not have one to confirm and I am going on documentation rather than measurement. Worth widening if you can verify it. It fails cleanly with exit 4, so this is coverage rather than a defect.

Everything else checks out. I ran this against a live controller and the output was correct, and fmt, clippy -D warnings, the test suite and clispec 0.3 all pass.

These four PRs overlap in client.rs, types.rs, main.rs, schema.rs and mock_server.rs, so whichever lands first makes the others conflict. That is my sequencing problem more than yours: I am landing #5 first, and if you would rather not chase rebases across three branches, say so and I will resolve the conflicts on merge.

@rvben
rvben merged commit ddc4feb into rvben:main Aug 18, 2026
5 checks passed
@Kampe
Kampe deleted the agent/wan-status branch October 3, 2026 19:23
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.

2 participants