Documentation ¶
Index ¶
- Constants
- Variables
- func ClientPoints(c *unifi.Client, now time.Time) ([]*influx.Point, error)
- func IDSPoints(i *unifi.IDS) ([]*influx.Point, error)
- func SitePoints(u *unifi.Site, now time.Time) ([]*influx.Point, error)
- func Start() error
- func StringInSlice(str string, slice []string) bool
- func UAPPoints(u *unifi.UAP, now time.Time) ([]*influx.Point, error)
- func UDMPoints(u *unifi.UDM, now time.Time) ([]*influx.Point, error)
- func USGPoints(u *unifi.USG, now time.Time) ([]*influx.Point, error)
- func USWPoints(u *unifi.USW, now time.Time) ([]*influx.Point, error)
- type Config
- type Duration
- type Flag
- type Metrics
- type UnifiPoller
- func (u *UnifiPoller) AugmentMetrics(metrics *Metrics) error
- func (u *UnifiPoller) CheckSites() error
- func (u *UnifiPoller) CollectAndReport() error
- func (u *UnifiPoller) CollectMetrics() (*Metrics, error)
- func (u *UnifiPoller) DumpJSONPayload() (err error)
- func (u *UnifiPoller) GetFilteredSites() (unifi.Sites, error)
- func (u *UnifiPoller) GetInfluxDB() (err error)
- func (u *UnifiPoller) GetUnifi() (err error)
- func (u *UnifiPoller) LogDebugf(m string, v ...interface{})
- func (u *UnifiPoller) LogError(err error, prefix string)
- func (u *UnifiPoller) LogErrorf(m string, v ...interface{})
- func (u *UnifiPoller) Logf(m string, v ...interface{})
- func (u *UnifiPoller) PollController() error
- func (u *UnifiPoller) PrintRawAPIJSON(apiPath string) error
- func (u *UnifiPoller) ReportMetrics(metrics *Metrics) error
- func (u *UnifiPoller) Run() (err error)
Constants ¶
const DefaultConfFile = "/etc/unifi-poller/up.conf"
DefaultConfFile is where to find config is --config is not prvided.
const ENVConfigPrefix = "UP_"
ENVConfigPrefix is the prefix appended to an env variable tag name before retrieving the value from the OS.
Variables ¶
var Version = "development"
Version is injected by the Makefile
Functions ¶
func ClientPoints ¶ added in v1.5.3
ClientPoints generates Unifi Client datapoints for InfluxDB. These points can be passed directly to influx.
func IDSPoints ¶ added in v1.5.3
IDSPoints generates intrusion detection datapoints for InfluxDB. These points can be passed directly to influx.
func SitePoints ¶ added in v1.5.3
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 ¶
StringInSlice returns true if a string is in a slice.
func UAPPoints ¶ added in v1.5.3
UAPPoints generates Wireless-Access-Point datapoints for InfluxDB. These points can be passed directly to influx.
func UDMPoints ¶ added in v1.5.3
UDMPoints generates Unifi Gateway 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.
type Duration ¶
Duration is used to UnmarshalTOML into a time.Duration value.
func (*Duration) UnmarshalText ¶
UnmarshalText parses a duration type from a config file.
type Metrics ¶
type Metrics struct { TS time.Time unifi.Sites unifi.IDSList unifi.Clients *unifi.Devices influx.BatchPoints }
Metrics contains all the data from the controller and an influx endpoint to send it to.
func (*Metrics) ProcessPoints ¶
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.