influxunifi

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2023 License: MIT, MIT Imports: 17 Imported by: 0

README

UnPoller InfluxDB Plugin

Collects UniFi data from a UniFi controller using the API.

This is meant for InfluxDB users 1.8+ and 2.x series.

Configuration

InfluxDB 1.8+, 2.x

Note the use of auth_token to enable this mode.

influxdb:
  disable: false
  # How often to poll UniFi and report to Datadog.
  interval: "2m"
  # the influxdb url to post data
  url: http://somehost:1234
  # the secret auth token, this enables InfluxDB 1.8, 2.x compatibility.
  auth_token: somesecret
  # the influxdb org
  org: my-org
  # the influxdb bucket
  bucket: my-bucket
  # how many points to batch write per flush.
  batch_size: 20

InfluxDB pre 1.8

Note the lack of auth_token to enable this mode.

influxdb:
  disable: false
  # How often to poll UniFi and report to Datadog.
  interval: "2m"
  # the influxdb url to post data
  url: http://somehost:1234
  # the database
  db: mydb
  # the influxdb api user
  user: unifi
  # the influxdb api password 
  pass: supersecret

Documentation

Overview

Package influxunifi provides the methods to turn UniFi measurements into influx data-points with appropriate tags and fields.

Index

Constants

View Source
const PluginName = "influxdb"

PluginName is the name of this plugin.

Variables

This section is empty.

Functions

func Combine

func Combine(in ...map[string]any) map[string]any

Combine concatenates N maps. This will delete things if not used with caution.

Types

type Config

type Config struct {
	Interval cnfg.Duration `json:"interval,omitempty" toml:"interval,omitempty" xml:"interval" yaml:"interval"`

	// Pass controls the influxdb v1 password to write metrics with
	Pass string `json:"pass,omitempty" toml:"pass,omitempty" xml:"pass" yaml:"pass"`
	// User controls the influxdb v1 user to write metrics with
	User string `json:"user,omitempty" toml:"user,omitempty" xml:"user" yaml:"user"`
	// DB controls the influxdb v1 database to write metrics to
	DB string `json:"db,omitempty" toml:"db,omitempty" xml:"db" yaml:"db"`

	// AuthToken is the secret for v2 influxdb
	AuthToken string `json:"auth_token,omitempty" toml:"auth_token,omitempty" xml:"auth_token" yaml:"auth_token"`
	// Org is the influx org to put metrics under for v2 influxdb
	Org string `json:"org,omitempty" toml:"org,omitempty" xml:"org" yaml:"org"`
	// Bucket is the influx bucket to put metrics under for v2 influxdb
	Bucket string `json:"bucket,omitempty" toml:"bucket,omitempty" xml:"bucket" yaml:"bucket"`
	// BatchSize controls the async batch size for v2 influxdb client mode
	BatchSize uint `json:"batch_size,omitempty" toml:"batch_size,omitempty" xml:"batch_size" yaml:"batch_size"`

	// URL details which influxdb url to use to report metrics to.
	URL string `json:"url,omitempty" toml:"url,omitempty" xml:"url" yaml:"url"`
	// Disable when true will disable the influxdb output.
	Disable bool `json:"disable" toml:"disable" xml:"disable,attr" yaml:"disable"`
	// VerifySSL when true will require ssl verification.
	VerifySSL bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"`
	// DeadPorts when true will save data for dead ports, for example ports that are down or disabled.
	DeadPorts bool `json:"dead_ports" toml:"dead_ports" xml:"dead_ports" yaml:"dead_ports"`
}

Config defines the data needed to store metrics in InfluxDB.

type Counts

type Counts struct {
	Val map[item]int
	sync.RWMutex
}

Counts holds counters and has a lock to deal with routines.

type InfluxDB

type InfluxDB struct {
	*Config `json:"influxdb" toml:"influxdb" xml:"influxdb" yaml:"influxdb"`
}

InfluxDB allows the data to be nested in the config file.

type InfluxUnifi

type InfluxUnifi struct {
	Collector poller.Collect

	LastCheck  time.Time
	IsVersion2 bool
	*InfluxDB
	// contains filtered or unexported fields
}

InfluxUnifi is returned by New() after you provide a Config.

func (*InfluxUnifi) DebugOutput

func (u *InfluxUnifi) DebugOutput() (bool, error)

func (*InfluxUnifi) Enabled

func (u *InfluxUnifi) Enabled() bool

func (*InfluxUnifi) LogDebugf

func (u *InfluxUnifi) LogDebugf(msg string, v ...any)

LogDebugf logs a debug message.

func (*InfluxUnifi) LogErrorf

func (u *InfluxUnifi) LogErrorf(msg string, v ...any)

LogErrorf logs an error message.

func (*InfluxUnifi) Logf

func (u *InfluxUnifi) Logf(msg string, v ...any)

Logf logs a message.

func (*InfluxUnifi) PollController

func (u *InfluxUnifi) PollController()

PollController runs forever, polling UniFi and pushing to InfluxDB This is started by Run() or RunBoth() after everything checks out.

func (*InfluxUnifi) ReportMetrics

func (u *InfluxUnifi) ReportMetrics(m *poller.Metrics, e *poller.Events) (*Report, error)

ReportMetrics batches all device and client data into influxdb data points. Call this after you've collected all the data you care about. Returns an error if influxdb calls fail, otherwise returns a report.

func (*InfluxUnifi) Run

func (u *InfluxUnifi) Run(c poller.Collect) error

Run runs a ticker to poll the unifi server and update influxdb.

type Report

type Report struct {
	UseV2   bool
	Metrics *poller.Metrics
	Events  *poller.Events
	Errors  []error
	Counts  *Counts
	Start   time.Time
	Elapsed time.Duration
	// contains filtered or unexported fields
}

Report is returned to the calling procedure after everything is processed.

func (*Report) String

func (r *Report) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL