Commit Graph

4899 Commits

Author SHA1 Message Date
Cody Lee
a94b530adf bump unifi version 2026-01-30 11:48:00 -06:00
Cody Lee
11450439fc Merge pull request #925 from brngates98/feat/wan-metrics
feat: Add WAN metrics export to Prometheus, InfluxDB, and Datadog
v2.27.0
2026-01-29 16:50:47 -06:00
brngates98
b96606128d chore: Update go.sum for unifi v5.11.0 and fix formatting
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-29 17:37:33 -05:00
brngates98
af6cbdf79f chore: Update unifi dependency to v5.11.0 for WAN metrics support
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-29 17:36:03 -05:00
brngates98
b8519ca058 feat: Add WAN metrics to InfluxDB and Datadog exporters
Add comprehensive WAN metrics support to InfluxDB and Datadog exporters:

InfluxDB Metrics (measurement: wan):
- Configuration: failover_priority, load_balance_weight, provider_download_kbps,
  provider_upload_kbps, smartq_enabled, magic_enabled, vlan_enabled
- Statistics: uptime_percentage, peak_download_percent, peak_upload_percent,
  max_rx_bytes_rate, max_tx_bytes_rate
- Service Provider: service_provider_asn
- Metadata: creation_timestamp

Tags: wan_id, wan_name, wan_networkgroup, wan_type, wan_load_balance_type,
      isp_name, isp_city

Datadog Metrics (namespace: unpoller.wan.*):
- Same metrics as InfluxDB with gauge type
- All metrics tagged with WAN and ISP information

Changes:
- pkg/influxunifi/wan.go: New WAN exporter for InfluxDB
- pkg/influxunifi/influxdb.go: Add WAN to loopPoints and switchExport
- pkg/datadogunifi/wan.go: New WAN exporter for Datadog
- pkg/datadogunifi/datadog.go: Add WAN to loopPoints and switchExport

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-29 17:27:28 -05:00
brngates98
aac4917da7 feat: Add WAN metrics export to Prometheus
Add comprehensive WAN metrics support to unpoller:

WAN Configuration Metrics:
- wan_failover_priority: WAN failover priority
- wan_load_balance_weight: Load balancing weight
- wan_provider_download_kbps: Configured ISP download speed
- wan_provider_upload_kbps: Configured ISP upload speed
- wan_smartq_enabled: SmartQueue QoS status
- wan_magic_enabled: Magic WAN status
- wan_vlan_enabled: VLAN configuration status

WAN Statistics Metrics:
- wan_uptime_percentage: WAN uptime percentage
- wan_peak_download_percent: Peak download utilization
- wan_peak_upload_percent: Peak upload utilization
- wan_max_rx_bytes_rate: Maximum receive rate
- wan_max_tx_bytes_rate: Maximum transmit rate

WAN Service Provider Metrics:
- wan_service_provider_asn: ISP autonomous system number

Labels include:
- wan_id, wan_name, wan_networkgroup
- wan_type (dhcp, static, pppoe)
- wan_load_balance_type (weighted, failover-only)
- isp_name, isp_city (service provider metrics)
- site_name, source

Changes:
- pkg/poller/config.go: Add WANConfigs field to Metrics struct
- pkg/poller/inputs.go: Append WAN configs in metric aggregation
- pkg/inputunifi/input.go: Add WANConfigs field to Metrics struct
- pkg/inputunifi/collector.go: Fetch WAN enriched configuration
- pkg/promunifi/wan.go: New WAN metrics exporter
- pkg/promunifi/collector.go: Initialize and export WAN metrics

Depends on: unpoller/unifi PR (WAN API support)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-29 17:24:12 -05:00
Cody Lee
d178da7c75 Merge pull request #924 from brngates98/feat/dhcp-client-monitoring
feat: Add DHCP lease metrics export to Prometheus
v2.26.0
2026-01-29 16:12:31 -06:00
brngates98
86bc1c9d6d fix: rename unused exportWithTags param to _ to satisfy revive
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-29 17:07:43 -05:00
Brian Gates
39b1b316a2 Merge branch 'master' into feat/dhcp-client-monitoring 2026-01-29 17:04:00 -05:00
brngates98
8769f8f121 chore: bump unifi to v5.10.0
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-01-29 17:02:38 -05:00
brngates98
3faaa3a696 fix: Remove local replace directive and update unifi to v5.8.0 to resolve go.sum conflicts 2026-01-28 21:48:33 -05:00
brngates98
74c30eabe6 feat: Add DHCP lease metrics export to Prometheus
- Add DHCP lease fetching in inputunifi collector
- Create promunifi/dhcp_leases.go with network-level and per-lease metrics
- Network-level metrics: pool_size, active_leases, utilization_percent, free_percent, available_ips
- Per-lease metrics: is_static, lease_end, lease_start, lease_time
- Separate network-level pool metrics from per-lease metrics
2026-01-28 21:42:44 -05:00
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
d26d84e8ad Merge pull request #923 from unpoller/issue-921
fix client side log error
v2.25.0
2026-01-27 21:16:14 -06:00
Cody Lee
5e68016564 fix client side log error 2026-01-27 21:14:21 -06:00
Cody Lee
a14d5c4150 Merge pull request #922 from brngates98/add-ai-context-files
Add AI context files for major LLMs
2026-01-27 20:51:34 -06:00
brngates98
969445fade Add AI context files for major LLMs
- Add .cursorrules for Cursor AI
- Add CLAUDE.md for Claude Code
- Add AGENTS.md for universal AI agent context
- Add .github/copilot-instructions.md for GitHub Copilot

These files provide comprehensive context about the UnPoller project
architecture, coding standards, and development patterns to help AI
coding assistants understand and work with the codebase effectively.
2026-01-27 20:40:02 -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