Commit Graph

4883 Commits

Author SHA1 Message Date
brngates98
6d85ea76ab Add device tag support to Prometheus metrics
- Add 'tag' label to all device metric descriptors
- Update exportWithTags helper to create separate metric series per tag
- Update all device export functions (UAP, USW, UDM, USG, UXG, PDU, UBB, UCI) to include tags
- Update all label arrays (VAP, Radio, Port, etc.) to include tag label
- Devices with multiple tags create multiple metric series (one per tag)
- Devices without tags export with tag=""

Requires unpoller/unifi#92
2026-01-28 20:48:10 -05:00
Cody Lee
2a44b2f0be Merge pull request #920 from unpoller/issue-742
Fix Homebrew formula for newer Homebrew versions
v2.24.0
2026-01-25 12:29:57 -06:00
Cody Lee
3f60654a2a Fix Homebrew formula for newer Homebrew versions
Updated the install section in the brews configuration to use the
new Homebrew formula syntax for directory creation.

Changes:
- Changed `etc.mkdir "unpoller"` to `(etc/"unpoller").mkpath`

The old syntax was causing errors with newer Homebrew versions:
  TypeError: no implicit conversion of String into Integer

This fix ensures compatibility with Homebrew 4.3+ while maintaining
backward compatibility with older versions.

Fixes #742

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 12:29:13 -06:00
Cody Lee
037f4563f0 Merge pull request #919 from unpoller/issue-415
Enrich alarms with device names for Loki logs
2026-01-25 12:22:39 -06:00
Cody Lee
0fc8b6f008 use new unifi version 2026-01-25 12:21:16 -06:00
Cody Lee
97d3f995b1 Enrich alarms with device names for Loki logs
Added device name enrichment to alarms so that Loki logs show
human-readable device names instead of just MAC addresses.

Changes:
- Modified collectAlarms to fetch devices and build MAC-to-name lookup
- Added extractDeviceNameFromAlarm helper to extract MAC addresses from
  alarm messages and lookup corresponding device names
- Device names are extracted from messages like "AP[fc:ec:da:89:a6:91]"
  or from SrcMAC/DstMAC fields
- Added go.mod replace directive to use local unifi library with new
  DeviceName field

The device_name field will now be included in the JSON output sent to
Loki, making it easier to identify which device triggered an alarm.

Fixes #415

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 12:17:12 -06:00
Cody Lee
a35e52c140 Merge pull request #918 from unpoller/issue-417
Populate num_user field for VPN subsystem metrics
2026-01-25 12:10:53 -06:00
Cody Lee
ae1ab40386 Populate num_user field for VPN subsystem metrics
Fixes #417

UniFi controllers populate RemoteUserNumActive for VPN connections but
leave NumUser at 0 for the VPN subsystem. This caused dashboard queries
looking for num_user in the VPN subsystem to always show 0 active users,
even when VPN connections were active.

Root Cause:
For most subsystems (wlan, lan, www), the controller populates NumUser
directly. However, for the VPN subsystem, the controller uses the
RemoteUserNumActive field instead, leaving NumUser at 0.

The Prometheus exporter had special handling for VPN (lines 148-156 in
pkg/promunifi/site.go) and exported RemoteUserNumActive, but did not
export NumUser. The InfluxDB and Datadog exporters exported all fields
for all subsystems without special handling, resulting in num_user
always being 0 for VPN.

Existing Grafana dashboards query:
  SELECT "num_user" FROM "subsystems" WHERE subsystem='vpn'

This always returned 0 even with active VPN users.

Solution:
For all three exporters (InfluxDB, Datadog, Prometheus), when the
subsystem is 'vpn' and NumUser is 0 but RemoteUserNumActive has a
value, populate num_user with RemoteUserNumActive.

Changes:
- pkg/influxunifi/site.go: Add VPN-specific num_user fallback logic
- pkg/datadogunifi/site.go: Add VPN-specific num_user fallback logic
- pkg/promunifi/site.go: Add NumUser metric to VPN case with fallback

This maintains backward compatibility - existing queries for num_user
will now work correctly, and the remote_user_num_active field is still
available for those who updated their dashboards.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 12:09:01 -06:00
Cody Lee
10a43dcf04 Merge pull request #917 from unpoller/issue-425
Allow polling to continue when individual controllers fail
2026-01-25 12:04:38 -06:00
Cody Lee
f51a0c7202 Allow polling to continue when individual controllers fail
Fixes #425

When polling multiple controllers, if one controller was down or
unreachable, unpoller would stop collecting data from ALL controllers.
This caused complete data loss across all sites when just one was down.

Root Cause:
Both Metrics() and Events() methods would immediately return an error
when any controller failed, skipping all remaining controllers in the
loop.

Changes:
- Log errors from failed controllers but continue to next controller
- Track collection errors separately from successful data collection
- Only return error if ALL controllers failed and no data was collected
- Return success if at least one controller provided data

This allows unpoller to continue monitoring healthy controllers even
when some are temporarily unreachable due to network issues, timeouts,
or maintenance.

Example behavior:
- Controller 1: Down (timeout) - logs error, continues
- Controller 2: Up - collects data successfully
- Controller 3: Up - collects data successfully
- Result: Returns data from controllers 2 and 3

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 12:01:37 -06:00
Cody Lee
4e3c823989 Merge pull request #916 from unpoller/issue-904
Fix authentication retry to prevent data gaps after re-auth
v2.23.0
2026-01-25 11:55:47 -06:00
Cody Lee
a1a8963159 Fix authentication retry to prevent data gaps after re-auth
Fixes #904

When a poll fails (typically with 401 Unauthorized after ~2 hour token
expiration), the code would re-authenticate but then return the original
poll error without retrying. This caused a one-minute data gap every
2 hours.

Changes:
- After successful re-authentication, retry the poll operation
- Add 500ms delay before retry to allow controller to process new auth
- Rename error variable to avoid shadowing during re-auth attempt

This ensures that transient authentication failures during the re-auth
window don't cause data gaps.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 11:53:31 -06:00
Cody Lee
092dd69509 Merge pull request #915 from unpoller/issue-910
Allow PoE-providing ports to be scraped even when disabled
2026-01-25 11:45:57 -06:00
Cody Lee
9e3debd58a Allow PoE-providing ports to be scraped even when disabled
Ports providing PoE power are no longer considered "dead" even when
disabled or down. This allows users to collect PoE metrics from ports
that are disabled for security reasons but still providing power.

Fixes #910

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 11:31:39 -06:00
Cody Lee
347467a969 Merge pull request #914 from unpoller/issue-912
Add configuration option to suppress unknown device type messages
2026-01-25 11:28:16 -06:00
Cody Lee
07781214c3 Add config option to suppress unknown device type messages
Adds log_unknown_types config option (default: false) to control logging
of unknown UniFi device types. When disabled (default), unknown devices
are silently ignored to reduce log volume. When enabled, they are logged
as DEBUG messages instead of ERROR. Addresses issue #912.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 11:24:33 -06:00
Cody Lee
2c20013ac6 Merge pull request #913 from brngates98/master
Add remote API support for UniFi Site Manager
v2.22.0
2026-01-25 11:10:09 -06:00
brngates98
1235430478 Update to unifi library v5.6.0 and fix linter errors
- Update go.mod to use unifi library v5.6.0 (includes remote API support)
- Remove temporary replace directive now that v5.6.0 is published
- Fix empty-block linter errors in input.go by removing empty if blocks
2026-01-25 10:58:08 -05:00
brngates98
e17d8bf62e move remote.go to use unifi library functions 2026-01-25 08:59:11 -05:00
brngates98
0cb331a745 Fix golangci-lint empty-block errors in input.go
Remove empty if blocks by inverting conditions:
- Line 289: Invert Remote check for URL default
- Line 303: Invert APIKey check in Remote mode
- Line 401: Invert Remote check for URL default in setControllerDefaults
2026-01-25 08:34:06 -05:00
brngates98
28e77d1ac5 Fix site name override for DPI clients, anomalies, and site metrics
- Apply site name override to DPI clients (ClientsDPI) in augmentMetrics
- Apply site name override to client anomalies when collecting events
- Apply site name override to sites (both Name and SiteName fields) when adding to metrics
- Apply site name override to DPI sites, speed tests, and country traffic
- Move applySiteNameOverride call to end of augmentMetrics to ensure all metrics are processed
- This ensures all Prometheus metrics use console names instead of 'Default (default)' for Cloud Gateways
2026-01-24 22:26:49 -05:00
brngates98
3996fd8683 Format code with gofmt 2026-01-24 18:22:40 -05:00
brngates98
d0abba6ddb Improve site name override to handle all default site name variations
- Add isDefaultSiteName helper to match any site name containing 'default' (case-insensitive)
- Handles variations like 'Default', 'default', 'Default (default)', etc.
- Ensures site_name in metrics shows console names instead of generic 'Default' values
- Makes metrics more compatible with existing dashboards that expect meaningful site names
- Also checks SiteName field on sites in addition to Name field
2026-01-24 18:22:34 -05:00
brngates98
1440f1426e Fix site name override for remote API Cloud Gateways
- Keep actual site name 'default' for API calls to prevent 404 errors
- Apply site name override only in metrics for display purposes
- Fixes issue where console names were used in API paths causing 404s
- Site name override now correctly applied to devices, clients, sites, and rogue APs in metrics only
2026-01-24 17:46:32 -05:00
brngates98
5f76c59fa2 fix duplicate controllers due to cloud gateways site being default 2026-01-24 17:42:54 -05:00
brngates98
28eae6ab22 Add remote API support for UniFi Site Manager
- Add remote API mode with automatic controller discovery
- Discover consoles via /v1/hosts endpoint
- Auto-discover sites for each console via integration API
- Use console name from hosts response as site name override for Cloud Gateways
- Support both config-level and per-controller remote mode
- Add example configs for YAML, JSON, and TOML formats
- Remote API uses api.ui.com with X-API-Key authentication
- Automatically discovers all consoles when remote=true and remote_api_key is set

This enables monitoring multiple UniFi Cloud Gateways through a single
API key without requiring direct network access to each controller.
2026-01-24 17:32:36 -05:00
Cody Lee
1df4ba9932 Merge pull request #908 from unpoller/dependabot/go_modules/all-cf2caa1bb8
Bump golang.org/x/crypto from 0.46.0 to 0.47.0 in the all group
2026-01-23 16:10:14 -07:00
dependabot[bot]
dc0cacd615 Bump golang.org/x/crypto from 0.46.0 to 0.47.0 in the all group
Bumps the all group with 1 update: [golang.org/x/crypto](https://github.com/golang/crypto).


Updates `golang.org/x/crypto` from 0.46.0 to 0.47.0
- [Commits](https://github.com/golang/crypto/compare/v0.46.0...v0.47.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.47.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-19 02:53:41 +00:00
Cody Lee
f47b463384 Merge pull request #907 from unpoller/dependabot/go_modules/all-0542acbba5 2026-01-13 06:02:42 -06:00
dependabot[bot]
2a2dfb0e59 Bump the all group with 2 updates
Bumps the all group with 2 updates: [github.com/prometheus/common](https://github.com/prometheus/common) and [golang.org/x/term](https://github.com/golang/term).


Updates `github.com/prometheus/common` from 0.67.4 to 0.67.5
- [Release notes](https://github.com/prometheus/common/releases)
- [Changelog](https://github.com/prometheus/common/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/common/compare/v0.67.4...v0.67.5)

Updates `golang.org/x/term` from 0.38.0 to 0.39.0
- [Commits](https://github.com/golang/term/compare/v0.38.0...v0.39.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/common
  dependency-version: 0.67.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: golang.org/x/term
  dependency-version: 0.39.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-12 02:46:23 +00:00
Cody Lee
c71cc9a681 Merge pull request #905 from aharper343/fix/nil-dereference v2.21.0 2025-12-24 13:25:50 -06:00
aharper343
25ba0bd14a Fix incorrect initialization of SaveTraffic 2025-12-24 14:08:47 -05:00
Cody Lee
db85517166 Merge pull request #903 from aharper343/feat/traffic-support 2025-12-24 12:55:07 -06:00
aharper343
f7d488a887 Lint and format cleanup 2025-12-24 12:09:19 -05:00
aharper343
9b62519bfe Rebasing 2025-12-24 00:25:09 -05:00
aharper343
6205900446 Adding constants for periods and debug logs for retrieved counts 2025-12-24 00:23:05 -05:00
aharper343
ab7073d63d Added support for regions and sub-regions 2025-12-24 00:23:05 -05:00
aharper343
22dfc25801 Temp fix for test cases and warning from Dockerfile 2025-12-24 00:23:05 -05:00
aharper343
0b9d3de5cc First working version DPI metrics and traffic exported 2025-12-24 00:23:00 -05:00
Cody Lee
bb4a4c823f Merge pull request #902 from svennergr/fix/http-timeout-config v2.20.1 2025-12-23 07:55:44 -06:00
Sven Grossmann
7e59c4883b fix: add HTTP timeout configuration to prevent indefinite hangs
The UniFi controller HTTP client was created without a timeout, causing
unpoller to hang indefinitely when the controller becomes unresponsive.
This resulted in random stops where polling would cease until the
container was restarted.

Changes:
- Add Timeout field to Controller struct (cnfg.Duration)
- Set default timeout of 60 seconds
- Pass timeout to unifi.Config when creating the client
- Log timeout value on startup for visibility

The timeout can be configured via:
- Config file: timeout = "60s"
- Environment: UP_UNIFI_DEFAULT_TIMEOUT=60s

Fixes issue where container would hang overnight:
  2025/12/22 22:29:27 - Requesting https://unifi/.../stat/sta
  [~2 hour gap - request hung indefinitely]
  2025/12/23 00:17:57 - Unmarshalling Device Type: udm...
2025-12-23 11:13:54 +01:00
Cody Lee
0d39302c19 Merge pull request #901 from svennergr/feature/protect-logs
feat: add UniFi Protect logs support with Loki integration
v2.20.0
2025-12-22 17:14:22 -06:00
Sven Grossmann
7e7fd0ff12 chore: upgrade to unifi 5.5.0 2025-12-22 23:41:24 +01:00
Sven Grossmann
07e1e5bc4d feat: add UniFi Protect logs support with Loki integration
- Add SaveProtectLogs config option to enable Protect log collection
- Add ProtectThumbnails config option to fetch event thumbnails
- Add collectProtectLogs function with 24h default fetch window
- Add ProtectLogEvent for Loki reporting with separate thumbnail log lines
- Add PII redaction for Protect log entries
- Filter thumbnail fetching to camera events only (motion, smartDetect*, etc.)
- Update log output to show Protect logs status
2025-12-22 22:55:30 +01:00
Cody Lee
703dff9b1e Merge pull request #900 from svennergr/svennergr/add-syslog 2025-12-22 11:33:22 -06:00
Sven Grossmann
02c7b6afa4 chore: upgrade to unifi 5.4.0 2025-12-22 18:16:00 +01:00
Sven Grossmann
47267073ac chore: comment out local replace directive for unifi module in go.mod 2025-12-22 17:28:42 +01:00
Sven Grossmann
a3dc4cd0b2 feat: add save_syslog option for v2 system-log API
Add new save_syslog config option to collect events from the v2 UniFi
system-log API (/v2/api/site/{site}/system-log/all).

Changes:
- Add SaveSyslog field to Controller struct
- Add collectSyslog() function using v2 API
- Keep collectEvents() using v1 API for backwards compatibility
- Add RedactIPPII() helper for PII redaction
- Update lokiunifi to log raw JSON (parseable with Loki | json)
- Reduce indexed labels to low-cardinality fields only
- Add SystemLogEntry handler in lokiunifi report

Config: save_syslog (v2 API) vs save_events (v1 API)
Env: UP_UNIFI_DEFAULT_SAVE_SYSLOG=true
2025-12-22 17:23:53 +01:00
Cody Lee
966cac1053 Merge pull request #899 from unpoller/dependabot/go_modules/all-74468f11a3 2025-12-15 05:56:36 -06:00
dependabot[bot]
0ab6e30d42 Bump github.com/DataDog/datadog-go/v5 in the all group
Bumps the all group with 1 update: [github.com/DataDog/datadog-go/v5](https://github.com/DataDog/datadog-go).


Updates `github.com/DataDog/datadog-go/v5` from 5.8.1 to 5.8.2
- [Release notes](https://github.com/DataDog/datadog-go/releases)
- [Changelog](https://github.com/DataDog/datadog-go/blob/master/CHANGELOG.md)
- [Commits](https://github.com/DataDog/datadog-go/compare/v5.8.1...v5.8.2)

---
updated-dependencies:
- dependency-name: github.com/DataDog/datadog-go/v5
  dependency-version: 5.8.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-15 02:01:23 +00:00