Merge pull request #121 from davidnewhall/dn2_fixes

Fix some bugs.
This commit is contained in:
David Newhall II 2019-09-21 00:53:01 -07:00 committed by GitHub
commit 0d1a1cb308
13 changed files with 59 additions and 45 deletions

View File

@ -11,7 +11,7 @@ HBREPO="golift/homebrew-mugs"
MAINT="David Newhall II <david at sleepers dot pro>" MAINT="David Newhall II <david at sleepers dot pro>"
VENDOR="Go Lift <code at golift dot io>" VENDOR="Go Lift <code at golift dot io>"
DESC="Polls a UniFi controller and exports metrics to InfluxDB" DESC="Polls a UniFi controller and exports metrics to InfluxDB"
GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll -D funlen" GOLANGCI_LINT_ARGS="--enable-all -D gochecknoglobals -D dupl -D lll -D funlen -e G402"
# Example must exist at examples/$CONFIG_FILE.example # Example must exist at examples/$CONFIG_FILE.example
CONFIG_FILE="up.conf" CONFIG_FILE="up.conf"
LICENSE="MIT" LICENSE="MIT"

View File

@ -22,20 +22,20 @@
revision = "fc22c7df067eefd070157f157893fbce961d6359" revision = "fc22c7df067eefd070157f157893fbce961d6359"
[[projects]] [[projects]]
digest = "1:c1b1102241e7f645bc8e0c22ae352e8f0dc6484b6cb4d132fa9f24174e0119e2" digest = "1:524b71991fc7d9246cc7dc2d9e0886ccb97648091c63e30eef619e6862c955dd"
name = "github.com/spf13/pflag" name = "github.com/spf13/pflag"
packages = ["."] packages = ["."]
pruneopts = "UT" pruneopts = "UT"
revision = "298182f68c66c05229eb03ac171abe6e309ee79a" revision = "2e9d26c8c37aae03e3f9d4e90b7116f5accb7cab"
version = "v1.0.3" version = "v1.0.5"
[[projects]] [[projects]]
digest = "1:8b8439a870abfe8df15cd9963fe7702d20fc55cd0f2375304b4eecc955b45902" digest = "1:e74d5f03545d51228b9539aaffc5eb8a692fcb22f38fa60253437b1fc063a73b"
name = "golift.io/unifi" name = "golift.io/unifi"
packages = ["."] packages = ["."]
pruneopts = "UT" pruneopts = "UT"
revision = "a96d3c9d2e02e41013974e6595f7df581cf194dc" revision = "2bdbccee871d4f36a4e1efa3463386ae70095033"
version = "v4.1.2" version = "v4.1.3"
[[projects]] [[projects]]
digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96" digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96"

View File

@ -130,6 +130,9 @@ is provided so the application can be easily adapted to any environment.
CREATE USER unifi WITH PASSWORD 'unifi' WITH ALL PRIVILEGES CREATE USER unifi WITH PASSWORD 'unifi' WITH ALL PRIVILEGES
GRANT ALL ON unifi TO unifi GRANT ALL ON unifi TO unifi
influx_insecure_ssl default: false
Setting this to true will allow use of InfluxDB with an invalid SSL certificate.
unifi_url default: https://127.0.0.1:8443 unifi_url default: https://127.0.0.1:8443
This is the URL where the UniFi Controller is available. This is the URL where the UniFi Controller is available.

View File

@ -43,6 +43,8 @@ influx_user = "unifi"
influx_pass = "unifi" influx_pass = "unifi"
# Be sure to create this database. # Be sure to create this database.
influx_db = "unifi" influx_db = "unifi"
# If your InfluxDB uses an invalid SSL cert, set this to true.
influx_insecure_ssl = false
# Make a read-only user in the UniFi Admin Settings. # Make a read-only user in the UniFi Admin Settings.
unifi_user = "influx" unifi_user = "influx"

View File

@ -9,6 +9,7 @@
"influx_user": "unifi", "influx_user": "unifi",
"influx_pass": "unifi", "influx_pass": "unifi",
"influx_db": "unifi", "influx_db": "unifi",
"influx_insecure_ssl": false,
"unifi_user": "influx", "unifi_user": "influx",
"unifi_pass": "", "unifi_pass": "",
"unifi_url": "https://127.0.0.1:8443", "unifi_url": "https://127.0.0.1:8443",

View File

@ -63,7 +63,10 @@
<influx_pass>unifi</influx_pass> <influx_pass>unifi</influx_pass>
<influx_url>http://127.0.0.1:8086</influx_url> <influx_url>http://127.0.0.1:8086</influx_url>
<influx_user>unifi</influx_user> <influx_user>unifi</influx_user>
<!--
# If your InfluxDB uses an invalid SSL cert, set this to true.
-->
<influx_insecure_ssl>false</influx_insecure_ssl>
<!-- <!--
# Make a read-only user in the UniFi Admin Settings. # Make a read-only user in the UniFi Admin Settings.

View File

@ -44,6 +44,8 @@ influx_user: "unifi"
influx_pass: "unifi" influx_pass: "unifi"
# Be sure to create this database. # Be sure to create this database.
influx_db: "unifi" influx_db: "unifi"
# If your InfluxDB uses an invalid SSL cert, set this to true.
influx_insecure_ssl: false
# Make a read-only user in the UniFi Admin Settings. # Make a read-only user in the UniFi Admin Settings.
unifi_user: "influx" unifi_user: "influx"

View File

@ -76,6 +76,7 @@ type Config struct {
VerifySSL bool `json:"verify_ssl" toml:"verify_ssl" xml:"verify_ssl" yaml:"verify_ssl" env:"VERIFY_SSL"` 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"` 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"` ReAuth bool `json:"reauthenticate" toml:"reauthenticate" xml:"reauthenticate" yaml:"reauthenticate" env:"REAUTHENTICATE"`
InfxBadSSL bool `json:"influx_insecure_ssl" toml:"influx_insecure_ssl" xml:"influx_insecure_ssl" yaml:"influx_insecure_ssl" env:"INFLUX_INSECURE_SSL"`
Mode string `json:"mode" toml:"mode" xml:"mode" yaml:"mode" env:"POLLING_MODE"` 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"` 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"` InfluxUser string `json:"influx_user,_omitempty" toml:"influx_user,_omitempty" xml:"influx_user" yaml:"influx_user" env:"INFLUX_USER"`

View File

@ -175,7 +175,7 @@ func processVAPs(vt unifi.VapTable, rt unifi.RadioTable, rts unifi.RadioTableSta
tags["channel"] = p.Channel.Txt tags["channel"] = p.Channel.Txt
tags["radio"] = p.Radio tags["radio"] = p.Radio
fields["current_antenna_gain"] = p.CurrentAntennaGain.Val fields["current_antenna_gain"] = p.CurrentAntennaGain.Val
fields["ht"] = p.Ht fields["ht"] = p.Ht.Txt
fields["max_txpower"] = p.MaxTxpower.Val fields["max_txpower"] = p.MaxTxpower.Val
fields["min_rssi_enabled"] = p.MinRssiEnabled.Val fields["min_rssi_enabled"] = p.MinRssiEnabled.Val
fields["min_txpower"] = p.MinTxpower.Val fields["min_txpower"] = p.MinTxpower.Val

View File

@ -169,7 +169,6 @@ func UDMPoints(u *unifi.UDM, now time.Time) ([]*influx.Point, error) {
"has_fan": u.HasFan.Txt, "has_fan": u.HasFan.Txt,
"has_temperature": u.HasTemperature.Txt, "has_temperature": u.HasTemperature.Txt,
"jumboframe_enabled": u.JumboframeEnabled.Txt, "jumboframe_enabled": u.JumboframeEnabled.Txt,
"stp_priority": u.StpPriority,
"stp_version": u.StpVersion, "stp_version": u.StpVersion,
} }
fields = map[string]interface{}{ fields = map[string]interface{}{
@ -198,6 +197,7 @@ func UDMPoints(u *unifi.UDM, now time.Time) ([]*influx.Point, error) {
"cpu": u.SystemStats.CPU.Val, "cpu": u.SystemStats.CPU.Val,
"mem": u.SystemStats.Mem.Val, "mem": u.SystemStats.Mem.Val,
"system_uptime": u.SystemStats.Uptime.Val, "system_uptime": u.SystemStats.Uptime.Val,
"stp_priority": u.StpPriority.Val,
"stat_bytes": u.Stat.Sw.Bytes.Val, "stat_bytes": u.Stat.Sw.Bytes.Val,
"stat_rx_bytes": u.Stat.Sw.RxBytes.Val, "stat_rx_bytes": u.Stat.Sw.RxBytes.Val,
"stat_rx_crypts": u.Stat.Sw.RxCrypts.Val, "stat_rx_crypts": u.Stat.Sw.RxCrypts.Val,

View File

@ -170,23 +170,23 @@ func USGPoints(u *unifi.USG, now time.Time) ([]*influx.Point, error) {
"is_nat": p.IsNat.Txt, "is_nat": p.IsNat.Txt,
"networkgroup": p.Networkgroup, "networkgroup": p.Networkgroup,
"site_id": p.SiteID, "site_id": p.SiteID,
}
fields := map[string]interface{}{
"domain_name": p.DomainName,
"dhcpd_start": p.DhcpdStart,
"dhcpd_stop": p.DhcpdStop,
"ip": p.IP, "ip": p.IP,
"ip_subnet": p.IPSubnet, "ip_subnet": p.IPSubnet,
"mac": p.Mac, "mac": p.Mac,
"name": p.Name, "name": p.Name,
"num_sta": p.NumSta.Val, "domain_name": p.DomainName,
"dhcpd_start": p.DhcpdStart,
"dhcpd_stop": p.DhcpdStop,
"ipv6_interface_type": p.Ipv6InterfaceType,
"attr_hidden_id": p.AttrHiddenID,
"purpose": p.Purpose, "purpose": p.Purpose,
}
fields := map[string]interface{}{
"num_sta": p.NumSta.Val,
"rx_bytes": p.RxBytes.Val, "rx_bytes": p.RxBytes.Val,
"rx_packets": p.RxPackets.Val, "rx_packets": p.RxPackets.Val,
"tx_bytes": p.TxBytes.Val, "tx_bytes": p.TxBytes.Val,
"tx_packets": p.TxPackets.Val, "tx_packets": p.TxPackets.Val,
"ipv6_interface_type": p.Ipv6InterfaceType,
"attr_hidden_id": p.AttrHiddenID,
} }
pt, err = influx.NewPoint("usg_networks", tags, fields, now) pt, err = influx.NewPoint("usg_networks", tags, fields, now)
if err != nil { if err != nil {

View File

@ -36,7 +36,6 @@ func USWPoints(u *unifi.USW, now time.Time) ([]*influx.Point, error) {
"has_fan": u.HasFan.Txt, "has_fan": u.HasFan.Txt,
"has_temperature": u.HasTemperature.Txt, "has_temperature": u.HasTemperature.Txt,
"jumboframe_enabled": u.JumboframeEnabled.Txt, "jumboframe_enabled": u.JumboframeEnabled.Txt,
"stp_priority": u.StpPriority,
"stp_version": u.StpVersion, "stp_version": u.StpVersion,
} }
fields := map[string]interface{}{ fields := map[string]interface{}{
@ -63,6 +62,7 @@ func USWPoints(u *unifi.USW, now time.Time) ([]*influx.Point, error) {
"mem_total": u.SysStats.MemTotal.Val, "mem_total": u.SysStats.MemTotal.Val,
"cpu": u.SystemStats.CPU.Val, "cpu": u.SystemStats.CPU.Val,
"mem": u.SystemStats.Mem.Val, "mem": u.SystemStats.Mem.Val,
"stp_priority": u.StpPriority.Val,
"system_uptime": u.SystemStats.Uptime.Val, "system_uptime": u.SystemStats.Uptime.Val,
"stat_bytes": u.Stat.Bytes.Val, "stat_bytes": u.Stat.Bytes.Val,
"stat_rx_bytes": u.Stat.RxBytes.Val, "stat_rx_bytes": u.Stat.RxBytes.Val,

View File

@ -1,6 +1,7 @@
package unifipoller package unifipoller
import ( import (
"crypto/tls"
"fmt" "fmt"
"log" "log"
"os" "os"
@ -99,6 +100,7 @@ func (u *UnifiPoller) GetInfluxDB() (err error) {
Addr: u.Config.InfluxURL, Addr: u.Config.InfluxURL,
Username: u.Config.InfluxUser, Username: u.Config.InfluxUser,
Password: u.Config.InfluxPass, Password: u.Config.InfluxPass,
TLSConfig: &tls.Config{InsecureSkipVerify: u.Config.InfxBadSSL},
}) })
if err != nil { if err != nil {
return fmt.Errorf("influxdb: %v", err) return fmt.Errorf("influxdb: %v", err)