inputunifi

package
v0.0.4 Latest Latest
Warning

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

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

README

inputunifi

UnPoller Input Plugin

Documentation

Overview

Package inputunifi implements the poller.Input interface and bridges the gap between metrics from the unifi library, and the augments required to pump them into unifi-poller.

Index

Constants

View Source
const PluginName = "unifi"

PluginName is the name of this input plugin.

Variables

View Source
var (
	ErrDynamicLookupsDisabled = fmt.Errorf("filter path requested but dynamic lookups disabled")
	ErrControllerNumNotFound  = fmt.Errorf("controller number not found")
	ErrNoFilterKindProvided   = fmt.Errorf("must provide filter: devices, clients, other")
)
View Source
var ErrScrapeFilterMatchFailed = fmt.Errorf("scrape filter match failed, and filter is not http URL")

Functions

func RedactMacPII

func RedactMacPII(pii string, hash *bool, dropPII *bool) (output string)

RedactMacPII converts a MAC address to an md5 hashed version (first 14 chars only). Useful for maskiing out personally identifying information.

func RedactNamePII

func RedactNamePII(pii string, hash *bool, dropPII *bool) string

RedactNamePII converts a name string to an md5 hash (first 24 chars only). Useful for maskiing out personally identifying information.

func StringInSlice

func StringInSlice(str string, slice []string) bool

StringInSlice returns true if a string is in a slice.

Types

type Config

type Config struct {
	sync.RWMutex               // locks the Unifi struct member when re-authing to unifi.
	Default      Controller    `json:"defaults" toml:"defaults" xml:"default" yaml:"defaults"`
	Disable      bool          `json:"disable" toml:"disable" xml:"disable,attr" yaml:"disable"`
	Dynamic      bool          `json:"dynamic" toml:"dynamic" xml:"dynamic,attr" yaml:"dynamic"`
	Controllers  []*Controller `json:"controllers" toml:"controller" xml:"controller" yaml:"controllers"`
}

Config contains our configuration data.

type Controller

type Controller struct {
	VerifySSL  *bool        `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl"`
	SaveAnomal *bool        `json:"save_anomalies" toml:"save_anomalies" xml:"save_anomalies" yaml:"save_anomalies"`
	SaveAlarms *bool        `json:"save_alarms" toml:"save_alarms" xml:"save_alarms" yaml:"save_alarms"`
	SaveEvents *bool        `json:"save_events" toml:"save_events" xml:"save_events" yaml:"save_events"`
	SaveIDS    *bool        `json:"save_ids" toml:"save_ids" xml:"save_ids" yaml:"save_ids"`
	SaveDPI    *bool        `json:"save_dpi" toml:"save_dpi" xml:"save_dpi" yaml:"save_dpi"`
	SaveRogue  *bool        `json:"save_rogue" toml:"save_rogue" xml:"save_rogue" yaml:"save_rogue"`
	HashPII    *bool        `json:"hash_pii" toml:"hash_pii" xml:"hash_pii" yaml:"hash_pii"`
	DropPII    *bool        `json:"drop_pii" toml:"drop_pii" xml:"drop_pii" yaml:"drop_pii"`
	SaveSites  *bool        `json:"save_sites" toml:"save_sites" xml:"save_sites" yaml:"save_sites"`
	CertPaths  []string     `json:"ssl_cert_paths" toml:"ssl_cert_paths" xml:"ssl_cert_path" yaml:"ssl_cert_paths"`
	User       string       `json:"user" toml:"user" xml:"user" yaml:"user"`
	Pass       string       `json:"pass" toml:"pass" xml:"pass" yaml:"pass"`
	URL        string       `json:"url" toml:"url" xml:"url" yaml:"url"`
	Sites      []string     `json:"sites" toml:"sites" xml:"site" yaml:"sites"`
	Unifi      *unifi.Unifi `json:"-" toml:"-" xml:"-" yaml:"-"`
	ID         string       `json:"id,omitempty"` // this is an output, not an input.
}

Controller represents the configuration for a UniFi Controller. Each polled controller may have its own configuration.

type InputUnifi

type InputUnifi struct {
	*Config `json:"unifi" toml:"unifi" xml:"unifi" yaml:"unifi"`

	sync.Mutex // to lock the map above.
	Logger     poller.Logger
	// contains filtered or unexported fields
}

InputUnifi contains the running data.

func (*InputUnifi) DebugInput

func (u *InputUnifi) DebugInput() (bool, error)

func (*InputUnifi) Events

func (u *InputUnifi) Events(filter *poller.Filter) (*poller.Events, error)

Events allows you to pull only events (and IDS) from the UniFi Controller. This does not fully respect HashPII, but it may in the future! Use Filter.Path to pick a specific controller, otherwise poll them all!

func (*InputUnifi) Initialize

func (u *InputUnifi) Initialize(l poller.Logger) error

Initialize gets called one time when starting up. Satisfies poller.Input interface.

func (*InputUnifi) LogDebugf

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

LogDebugf logs a debug message.

func (*InputUnifi) LogErrorf

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

LogErrorf logs an error message.

func (*InputUnifi) Logf

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

Logf logs a message.

func (*InputUnifi) Metrics

func (u *InputUnifi) Metrics(filter *poller.Filter) (*poller.Metrics, error)

Metrics grabs all the measurements from a UniFi controller and returns them. Set Filter.Path to a controller URL for a specific controller (or get them all).

func (*InputUnifi) RawMetrics

func (u *InputUnifi) RawMetrics(filter *poller.Filter) ([]byte, error)

RawMetrics returns API output from the first configured UniFi controller. Adjust filter.Unit to pull from a controller other than the first.

type Metrics

type Metrics struct {
	TS         time.Time
	Sites      []*unifi.Site
	Clients    []*unifi.Client
	SitesDPI   []*unifi.DPITable
	ClientsDPI []*unifi.DPITable
	RogueAPs   []*unifi.RogueAP
	Devices    *unifi.Devices
}

Metrics is simply a useful container for everything.

Jump to

Keyboard shortcuts

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