text and comment updates.
This commit is contained in:
parent
b65e9122ca
commit
9427980ae4
|
|
@ -63,10 +63,10 @@ too much opinion. If you want to provide a way to do something, please also prov
|
||||||
any alternatives you're aware of. If you're not sure, just open an issue and we can
|
any alternatives you're aware of. If you're not sure, just open an issue and we can
|
||||||
hash it out. I'm reasonable.
|
hash it out. I'm reasonable.
|
||||||
|
|
||||||
## Unifi Library
|
## UniFi Library
|
||||||
|
|
||||||
If you're trying to fix something in the unifi data collection (ie. you got an
|
If you're trying to fix something in the UniFi data collection (ie. you got an
|
||||||
unmarshal error, or you want to add something I didn't include) then you
|
unmarshal error, or you want to add something I didn't include) then you
|
||||||
should look at the [unifi library](https://github.com/golift/unifi). All the
|
should look at the [UniFi library](https://github.com/golift/unifi). All the
|
||||||
data collection and export code lives there. Contributions and Issues are welcome
|
data collection and export code lives there. Contributions and Issues are welcome
|
||||||
on that code base as well.
|
on that code base as well.
|
||||||
|
|
|
||||||
4
Makefile
4
Makefile
|
|
@ -1,10 +1,10 @@
|
||||||
# This Makefile is written as generic as possible.
|
# This Makefile is written as generic as possible.
|
||||||
# Setting these variables and creating the necesarry paths in your github repo will make this file work.
|
# Setting these variables and creating the necesarry paths in your GitHub repo will make this file work.
|
||||||
#
|
#
|
||||||
BINARY:=unifi-poller
|
BINARY:=unifi-poller
|
||||||
URL:=https://github.com/davidnewhall/$(BINARY)
|
URL:=https://github.com/davidnewhall/$(BINARY)
|
||||||
MAINT=David Newhall II <david at sleepers dot pro>
|
MAINT=David Newhall II <david at sleepers dot pro>
|
||||||
DESC=This daemon polls a Unifi controller at a short interval and stores the collected measurements in an Influx Database.
|
DESC=This daemon polls a UniFi controller at a short interval and stores the collected measurements in an Influx Database.
|
||||||
GOLANGCI_LINT_ARGS=--enable-all -D gochecknoglobals
|
GOLANGCI_LINT_ARGS=--enable-all -D gochecknoglobals
|
||||||
PACKAGE:=./cmd/$(BINARY)
|
PACKAGE:=./cmd/$(BINARY)
|
||||||
LIBRARY:=./pkg/$(BINARY)
|
LIBRARY:=./pkg/$(BINARY)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ Find them at [Grafana.com](https://grafana.com/dashboards?search=unifi-poller).
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
---
|
---
|
||||||
Unifi-Poller is a small Golang application that runs on Windows, macOS, Linux or
|
UniFi Poller is a small Golang application that runs on Windows, macOS, Linux or
|
||||||
Docker. It polls a UniFi controller every 30 seconds for measurements and stores
|
Docker. It polls a UniFi controller every 30 seconds for measurements and stores
|
||||||
the data in an Influx database. See the example configuration file for more
|
the data in an Influx database. See the example configuration file for more
|
||||||
examples and default configurations.
|
examples and default configurations.
|
||||||
|
|
@ -55,7 +55,7 @@ CONFIGURATION
|
||||||
* Possible formats: `XML`, `JSON`, `TOML`, `YAML`
|
* Possible formats: `XML`, `JSON`, `TOML`, `YAML`
|
||||||
|
|
||||||
The config file can be written in four different syntax formats. The application
|
The config file can be written in four different syntax formats. The application
|
||||||
decides which one to used based on the file's name. If it contains `.xml` it will
|
decides which one to use based on the file's name. If it contains `.xml` it will
|
||||||
be parsed as XML. The same goes for `.json` and `.yaml`. If the filename contains
|
be parsed as XML. The same goes for `.json` and `.yaml`. If the filename contains
|
||||||
none of these strings, then it is parsed as the default format, TOML. This option
|
none of these strings, then it is parsed as the default format, TOML. This option
|
||||||
is provided so the application can be easily adapted to any environment.
|
is provided so the application can be easily adapted to any environment.
|
||||||
|
|
@ -149,3 +149,4 @@ LOCATION
|
||||||
---
|
---
|
||||||
* UniFi Poller: [https://github.com/davidnewhall/unifi-poller](https://github.com/davidnewhall/unifi-poller)
|
* UniFi Poller: [https://github.com/davidnewhall/unifi-poller](https://github.com/davidnewhall/unifi-poller)
|
||||||
* UniFi Library: [https://github.com/golift/unifi](https://github.com/golift/unifi)
|
* UniFi Library: [https://github.com/golift/unifi](https://github.com/golift/unifi)
|
||||||
|
* Grafana Dashboards: [https://grafana.com/dashboards?search=unifi-poller](https://grafana.com/dashboards?search=unifi-poller)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class UnifiPoller < Formula
|
||||||
def caveats
|
def caveats
|
||||||
s = <<-EOS
|
s = <<-EOS
|
||||||
This application will not work until the config file has authentication
|
This application will not work until the config file has authentication
|
||||||
information for a Unifi Controller and an Influx Database. Edit the config
|
information for a UniFi Controller and an Influx Database. Edit the config
|
||||||
file at #{etc}/unifi-poller/up.conf then start the application with
|
file at #{etc}/unifi-poller/up.conf then start the application with
|
||||||
brew services start unifi-poller ~ log file: #{var}/log/unifi-poller.log
|
brew services start unifi-poller ~ log file: #{var}/log/unifi-poller.log
|
||||||
The manual explains the config file options: man unifi-poller
|
The manual explains the config file options: man unifi-poller
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Sytemd service unit for unifi-poller.
|
# Sytemd service unit for unifi-poller.
|
||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Unifi Poller - Stores Unifi Metrics in InfluxDB
|
Description=UniFi Poller - Stores UniFi Metrics in InfluxDB
|
||||||
After=network.target
|
After=network.target
|
||||||
Requires=network.target
|
Requires=network.target
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ type Asset interface {
|
||||||
Points() ([]*influx.Point, error)
|
Points() ([]*influx.Point, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnifiPoller contains the application startup data, and auth info for unifi & influx.
|
// UnifiPoller contains the application startup data, and auth info for UniFi & Influx.
|
||||||
type UnifiPoller struct {
|
type UnifiPoller struct {
|
||||||
ConfigFile string
|
ConfigFile string
|
||||||
DumpJSON string
|
DumpJSON string
|
||||||
|
|
@ -40,7 +40,7 @@ type UnifiPoller struct {
|
||||||
*Config
|
*Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metrics contains all the data from the controller and an influx endpoint to send them to.
|
// Metrics contains all the data from the controller and an influx endpoint to send it to.
|
||||||
type Metrics struct {
|
type Metrics struct {
|
||||||
unifi.Sites
|
unifi.Sites
|
||||||
unifi.Clients
|
unifi.Clients
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DumpJSONPayload prints raw json from the Unifi Controller.
|
// DumpJSONPayload prints raw json from the UniFi Controller.
|
||||||
func (u *UnifiPoller) DumpJSONPayload() (err error) {
|
func (u *UnifiPoller) DumpJSONPayload() (err error) {
|
||||||
u.Quiet = true
|
u.Quiet = true
|
||||||
u.Unifi, err = unifi.NewUnifi(u.UnifiUser, u.UnifiPass, u.UnifiBase, u.VerifySSL)
|
u.Unifi, err = unifi.NewUnifi(u.UnifiUser, u.UnifiPass, u.UnifiBase, u.VerifySSL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(os.Stderr, "[INFO] Authenticated to Unifi Controller @", u.UnifiBase, "as user", u.UnifiUser)
|
fmt.Fprintln(os.Stderr, "[INFO] Authenticated to UniFi Controller @", u.UnifiBase, "as user", u.UnifiUser)
|
||||||
if err := u.CheckSites(); err != nil {
|
if err := u.CheckSites(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +51,7 @@ func (u *UnifiPoller) dumpSitesJSON(path, name string, sites []unifi.Site) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintRawAPIJSON prints the raw json for a user-provided path on a Unifi Controller.
|
// PrintRawAPIJSON prints the raw json for a user-provided path on a UniFi Controller.
|
||||||
func (u *UnifiPoller) PrintRawAPIJSON(apiPath string) error {
|
func (u *UnifiPoller) PrintRawAPIJSON(apiPath string) error {
|
||||||
body, err := u.GetJSON(apiPath)
|
body, err := u.GetJSON(apiPath)
|
||||||
fmt.Println(string(body))
|
fmt.Println(string(body))
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func (u *UnifiPoller) Run() (err error) {
|
||||||
log.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
|
log.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
|
||||||
u.LogDebugf("Debug Logging Enabled")
|
u.LogDebugf("Debug Logging Enabled")
|
||||||
}
|
}
|
||||||
log.Printf("[INFO] Unifi-Poller v%v Starting Up! PID: %d", Version, os.Getpid())
|
log.Printf("[INFO] UniFi Poller v%v Starting Up! PID: %d", Version, os.Getpid())
|
||||||
|
|
||||||
if err = u.GetUnifi(); err != nil {
|
if err = u.GetUnifi(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -81,7 +81,7 @@ func (u *UnifiPoller) Run() (err error) {
|
||||||
return u.PollController()
|
return u.PollController()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInfluxDB returns an influxdb interface.
|
// GetInfluxDB returns an InfluxDB interface.
|
||||||
func (u *UnifiPoller) GetInfluxDB() (err error) {
|
func (u *UnifiPoller) GetInfluxDB() (err error) {
|
||||||
u.Client, err = influx.NewHTTPClient(influx.HTTPConfig{
|
u.Client, err = influx.NewHTTPClient(influx.HTTPConfig{
|
||||||
Addr: u.InfluxURL,
|
Addr: u.InfluxURL,
|
||||||
|
|
@ -95,7 +95,7 @@ func (u *UnifiPoller) GetInfluxDB() (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUnifi returns a Unifi controller interface.
|
// GetUnifi returns a UniFi controller interface.
|
||||||
func (u *UnifiPoller) GetUnifi() (err error) {
|
func (u *UnifiPoller) GetUnifi() (err error) {
|
||||||
// Create an authenticated session to the Unifi Controller.
|
// Create an authenticated session to the Unifi Controller.
|
||||||
u.Unifi, err = unifi.NewUnifi(u.UnifiUser, u.UnifiPass, u.UnifiBase, u.VerifySSL)
|
u.Unifi, err = unifi.NewUnifi(u.UnifiUser, u.UnifiPass, u.UnifiBase, u.VerifySSL)
|
||||||
|
|
@ -108,10 +108,10 @@ func (u *UnifiPoller) GetUnifi() (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
v.ServerVersion = "unknown"
|
v.ServerVersion = "unknown"
|
||||||
}
|
}
|
||||||
u.Logf("Authenticated to Unifi Controller at %s version %s as user %s", u.UnifiBase, v.ServerVersion, u.UnifiUser)
|
u.Logf("Authenticated to UniFi Controller at %s version %s as user %s", u.UnifiBase, v.ServerVersion, u.UnifiUser)
|
||||||
if err = u.CheckSites(); err != nil {
|
if err = u.CheckSites(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.Logf("Polling Unifi Controller Sites: %v", u.Sites)
|
u.Logf("Polling UniFi Controller Sites: %v", u.Sites)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@ FIRST:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PollController runs forever, polling unifi, and pushing to influx.
|
// PollController runs forever, polling UniFi, and pushing to influx.
|
||||||
|
// This is started by Run() after everything checks out.
|
||||||
func (u *UnifiPoller) PollController() error {
|
func (u *UnifiPoller) PollController() error {
|
||||||
log.Println("[INFO] Everything checks out! Poller started, interval:", u.Interval.Round(time.Second))
|
log.Println("[INFO] Everything checks out! Poller started, interval:", u.Interval.Round(time.Second))
|
||||||
ticker := time.NewTicker(u.Interval.Round(time.Second))
|
ticker := time.NewTicker(u.Interval.Round(time.Second))
|
||||||
|
|
@ -77,7 +78,7 @@ func (u *UnifiPoller) PollController() error {
|
||||||
i, _ := p.Fields()
|
i, _ := p.Fields()
|
||||||
fieldcount += len(i)
|
fieldcount += len(i)
|
||||||
}
|
}
|
||||||
u.Logf("Unifi Measurements Recorded. Sites: %d, Clients: %d, "+
|
u.Logf("UniFi Measurements Recorded. Sites: %d, Clients: %d, "+
|
||||||
"Wireless APs: %d, Gateways: %d, Switches: %d, Points: %d, Fields: %d",
|
"Wireless APs: %d, Gateways: %d, Switches: %d, Points: %d, Fields: %d",
|
||||||
len(m.Sites), len(m.Clients), len(m.UAPs), len(m.USGs), len(m.USWs), pointcount, fieldcount)
|
len(m.Sites), len(m.Clients), len(m.UAPs), len(m.USGs), len(m.USWs), pointcount, fieldcount)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue