mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:33:57 -04:00
- 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.
3.2 KiB
3.2 KiB
UnPoller - GitHub Copilot Instructions
Project Overview
UnPoller is a Go application that collects metrics and events from UniFi network controllers and exports them to monitoring backends (InfluxDB, Prometheus, Loki, DataDog, MySQL). The application uses a plugin-based architecture with a generic core.
Architecture
Plugin System
- Core Library (
pkg/poller/): Generic plugin system with input/output interfaces - Input Plugins: Collect data (e.g.,
pkg/inputunifi/) - Output Plugins: Export data to backends (e.g.,
pkg/influxunifi/,pkg/promunifi/) - Plugin Discovery: Automatic via blank imports in
main.go
Key Interfaces
Input Interface:
type Input interface {
GetMetrics() (*Metrics, error)
GetEvents() (*Events, error)
}
Output Interface:
type Output interface {
WriteMetrics(*Metrics) error
WriteEvents(*Events) error
}
Code Style
Go Conventions
- Go 1.25.5+
- Use
gofmtformatting - Follow
.golangci.yamllinting rules - Enabled linters:
nlreturn,revive,tagalign,testpackage,wsl_v5
Naming
- Packages:
lowercase - Exported:
PascalCase - Unexported:
camelCase - Errors: Always
err, check immediately
Error Handling
if err != nil {
return fmt.Errorf("context: %w", err)
}
Configuration
All config structs must include format tags:
type Config struct {
Field string `json:"field" toml:"field" xml:"field" yaml:"field"`
}
Environment variables use UP_ prefix.
Common Patterns
Plugin Registration
func init() {
poller.RegisterInput(&Input{})
// or
poller.RegisterOutput(&Output{})
}
Device Type Reporting
Each output plugin has device-specific functions:
UAP()- Access PointsUSG()- Security GatewaysUSW()- SwitchesUDM()- Dream MachinesUXG()- Next-Gen GatewaysUBB()- Building BridgesUCI()- Industrial devicesPDU()- Power Distribution Units
Adding New Plugin
- Create package in
pkg/ - Implement
InputorOutputinterface - Register in
init() - Add blank import to
main.go - Add config struct with tags
- Create
README.md
Dependencies
Core
github.com/unpoller/unifi/v5- UniFi API (local:/Users/briangates/unifi)golift.io/cnfg- Configurationgolift.io/cnfgfile- Config parsinggithub.com/spf13/pflag- CLI flags
Outputs
- InfluxDB:
github.com/influxdata/influxdb1-client,github.com/influxdata/influxdb-client-go/v2 - Prometheus:
github.com/prometheus/client_golang - DataDog:
github.com/DataDog/datadog-go/v5 - Loki: Custom HTTP client
Important Notes
pkg/pollercore is generic - no UniFi/backend knowledge- Support Windows, macOS, Linux, BSD
- Configuration: TOML (default), JSON, YAML, env vars
- Always check and return errors
- Use
context.Contextfor cancellable operations - Tests in
_testpackages - Use
github.com/stretchr/testifyfor assertions
When Writing Code
- Follow existing plugin patterns
- Keep core library generic
- Check all errors
- Document exported functions
- Write tests in
_testpackages - Consider cross-platform compatibility
- Use structured logging
- Respect timeouts and deadlines