unifipoller

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultConfFile = "/etc/unifi-poller/up.conf"

DefaultConfFile is where to find config is --config is not prvided.

View Source
const ENVConfigPrefix = "UP_"

ENVConfigPrefix is the prefix appended to an env variable tag name before retrieving the value from the OS.

Variables

View Source
var Version = "development"

Version is injected by the Makefile

Functions

func ClientPoints added in v1.5.3

func ClientPoints(c *unifi.Client, now time.Time) ([]*influx.Point, error)

ClientPoints generates Unifi Client datapoints for InfluxDB. These points can be passed directly to influx.

func IDSPoints added in v1.5.3

func IDSPoints(i *unifi.IDS) ([]*influx.Point, error)

IDSPoints generates intrusion detection datapoints for InfluxDB. These points can be passed directly to influx.

func SitePoints added in v1.5.3

func SitePoints(u *unifi.Site, now time.Time) ([]*influx.Point, error)

SitePoints generates Unifi Sites' datapoints for InfluxDB. These points can be passed directly to influx.

func Start

func Start() error

Start begins the application from a CLI. Parses flags, parses config and executes Run().

func StringInSlice

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

StringInSlice returns true if a string is in a slice.

func UAPPoints added in v1.5.3

func UAPPoints(u *unifi.UAP, now time.Time) ([]*influx.Point, error)

UAPPoints generates Wireless-Access-Point datapoints for InfluxDB. These points can be passed directly to influx.

func UDMPoints added in v1.5.3

func UDMPoints(u *unifi.UDM, now time.Time) ([]*influx.Point, error)

UDMPoints generates Unifi Gateway datapoints for InfluxDB. These points can be passed directly to influx.

func USGPoints added in v1.5.3

func USGPoints(u *unifi.USG, now time.Time) ([]*influx.Point, error)

USGPoints generates Unifi Gateway datapoints for InfluxDB. These points can be passed directly to influx.

func USWPoints added in v1.5.3

func USWPoints(u *unifi.USW, now time.Time) ([]*influx.Point, error)

USWPoints generates Unifi Switch datapoints for InfluxDB. These points can be passed directly to influx.

Types

type Config

type Config struct {
	Interval   Duration `json:"interval,omitempty" toml:"interval,omitempty" xml:"interval" yaml:"interval" env:"POLLING_INTERVAL"`
	Debug      bool     `json:"debug" toml:"debug" xml:"debug" yaml:"debug" env:"DEBUG_MODE"`
	Quiet      bool     `json:"quiet,omitempty" toml:"quiet,omitempty" xml:"quiet" yaml:"quiet" env:"QUIET_MODE"`
	VerifySSL  bool     `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl" env:"VERIFY_SSL"`
	CollectIDS bool     `json:"collect_ids" toml:"collect_ids" xml:"collect_ids" yaml:"collect_ids" env:"COLLECT_IDS"`
	ReAuth     bool     `json:"reauthenticate" toml:"reauthenticate" xml:"reauthenticate" yaml:"reauthenticate" env:"REAUTHENTICATE"`
	InfxBadSSL bool     `` /* 132-byte string literal not displayed */
	Mode       string   `json:"mode" toml:"mode" xml:"mode" yaml:"mode" env:"POLLING_MODE"`
	InfluxURL  string   `json:"influx_url,omitempty" toml:"influx_url,omitempty" xml:"influx_url" yaml:"influx_url" env:"INFLUX_URL"`
	InfluxUser string   `json:"influx_user,omitempty" toml:"influx_user,omitempty" xml:"influx_user" yaml:"influx_user" env:"INFLUX_USER"`
	InfluxPass string   `json:"influx_pass,omitempty" toml:"influx_pass,omitempty" xml:"influx_pass" yaml:"influx_pass" env:"INFLUX_PASS"`
	InfluxDB   string   `json:"influx_db,omitempty" toml:"influx_db,omitempty" xml:"influx_db" yaml:"influx_db" env:"INFLUX_DB"`
	UnifiUser  string   `json:"unifi_user,omitempty" toml:"unifi_user,omitempty" xml:"unifi_user" yaml:"unifi_user" env:"UNIFI_USER"`
	UnifiPass  string   `json:"unifi_pass,omitempty" toml:"unifi_pass,omitempty" xml:"unifi_pass" yaml:"unifi_pass" env:"UNIFI_PASS"`
	UnifiBase  string   `json:"unifi_url,omitempty" toml:"unifi_url,omitempty" xml:"unifi_url" yaml:"unifi_url" env:"UNIFI_URL"`
	Sites      []string `json:"sites,omitempty" toml:"sites,omitempty" xml:"sites" yaml:"sites" env:"POLL_SITES"`
}

Config represents the data needed to poll a controller and report to influxdb. This is all of the data stored in the config file. Any with explicit defaults have omitempty on json and toml tags.

func (*Config) ParseENV added in v1.5.3

func (c *Config) ParseENV() error

ParseENV copies environment variables into configuration values. This is useful for Docker users that find it easier to pass ENV variables than a specific configuration file. Uses reflection to find struct tags.

func (*Config) ParseFile added in v1.5.3

func (c *Config) ParseFile(configFile string) error

ParseFile parses and returns our configuration data.

type Duration

type Duration struct{ time.Duration }

Duration is used to UnmarshalTOML into a time.Duration value.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(data []byte) (err error)

UnmarshalText parses a duration type from a config file.

type Flag added in v1.5.3

type Flag struct {
	ConfigFile string
	DumpJSON   string
	ShowVer    bool
	*pflag.FlagSet
}

Flag represents the CLI args available and their settings.

func (*Flag) Parse added in v1.5.3

func (f *Flag) Parse(args []string)

Parse turns CLI arguments into data structures. Called by Start() on startup.

type Metrics

Metrics contains all the data from the controller and an influx endpoint to send it to.

func (*Metrics) ProcessPoints

func (m *Metrics) ProcessPoints() []error

ProcessPoints batches all device and client data into influxdb data points. Call this after you've collected all the data you care about. This function is sorta weird and returns a slice of errors. The reasoning is that some points may process while others fail, so we attempt to process them all. This is (usually) run in a loop, so we can't really exit on error, we just log the errors and tally them on a counter. In reality, this never returns any errors because we control the data going in; cool right? But we still check&log it in case the data going is skewed up and causes errors!

type UnifiPoller

type UnifiPoller struct {
	Influx influx.Client
	Unifi  *unifi.Unifi
	Flag   *Flag
	Config *Config

	LastCheck time.Time
	// contains filtered or unexported fields
}

UnifiPoller contains the application startup data, and auth info for UniFi & Influx.

func (*UnifiPoller) AugmentMetrics

func (u *UnifiPoller) AugmentMetrics(metrics *Metrics) error

AugmentMetrics is our middleware layer between collecting metrics and writing them. This is where we can manipuate the returned data or make arbitrary decisions. This function currently adds parent device names to client metrics.

func (*UnifiPoller) CheckSites

func (u *UnifiPoller) CheckSites() error

CheckSites makes sure the list of provided sites exists on the controller. This does not run in Lambda (run-once) mode.

func (*UnifiPoller) CollectAndReport

func (u *UnifiPoller) CollectAndReport() error

CollectAndReport collects measurements and reports them to influxdb. Can be called once or in a ticker loop. This function and all the ones below handle their own logging. An error is returned so the calling function may determine if there was a read or write error and act on it. This is currently called in two places in this library. One returns an error, one does not.

func (*UnifiPoller) CollectMetrics

func (u *UnifiPoller) CollectMetrics() (*Metrics, error)

CollectMetrics grabs all the measurements from a UniFi controller and returns them. This also creates an InfluxDB writer, and returns an error if that fails.

func (*UnifiPoller) DumpJSONPayload

func (u *UnifiPoller) DumpJSONPayload() (err error)

DumpJSONPayload prints raw json from the UniFi Controller.

func (*UnifiPoller) GetFilteredSites

func (u *UnifiPoller) GetFilteredSites() (unifi.Sites, error)

GetFilteredSites returns a list of sites to fetch data for. Omits requested but unconfigured sites. Grabs the full list from the controller and returns the sites provided in the config file.

func (*UnifiPoller) GetInfluxDB

func (u *UnifiPoller) GetInfluxDB() (err error)

GetInfluxDB returns an InfluxDB interface.

func (*UnifiPoller) GetUnifi

func (u *UnifiPoller) GetUnifi() (err error)

GetUnifi returns a UniFi controller interface.

func (*UnifiPoller) LogDebugf

func (u *UnifiPoller) LogDebugf(m string, v ...interface{})

LogDebugf prints a debug log entry if debug is true and quite is false

func (*UnifiPoller) LogError

func (u *UnifiPoller) LogError(err error, prefix string)

LogError logs an error and increments the error counter. Should be used in the poller loop.

func (*UnifiPoller) LogErrorf

func (u *UnifiPoller) LogErrorf(m string, v ...interface{})

LogErrorf prints an error log entry. This is used for external library logging.

func (*UnifiPoller) Logf

func (u *UnifiPoller) Logf(m string, v ...interface{})

Logf prints a log entry if quiet is false.

func (*UnifiPoller) PollController

func (u *UnifiPoller) PollController() error

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

func (*UnifiPoller) PrintRawAPIJSON

func (u *UnifiPoller) PrintRawAPIJSON(apiPath string) error

PrintRawAPIJSON prints the raw json for a user-provided path on a UniFi Controller.

func (*UnifiPoller) ReportMetrics

func (u *UnifiPoller) ReportMetrics(metrics *Metrics) error

ReportMetrics batches all the metrics and writes them to InfluxDB. Returns an error if the write to influx fails.

func (*UnifiPoller) Run

func (u *UnifiPoller) Run() (err error)

Run invokes all the application logic and routines.

Jump to

Keyboard shortcuts

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