From 035de35d842c16f128e73e9864b23e34d07bf7eb Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Fri, 19 Jun 2020 03:41:17 -0700 Subject: [PATCH 1/8] Update code for events --- core/poller/config.go | 19 ++++------- core/poller/dumper.go | 10 +++--- core/poller/go.mod | 2 +- core/poller/go.sum | 4 +++ core/poller/inputs.go | 72 ++++++++++++------------------------------ core/poller/outputs.go | 3 +- core/poller/start.go | 1 + 7 files changed, 37 insertions(+), 74 deletions(-) diff --git a/core/poller/config.go b/core/poller/config.go index 373d51f6..c4f49e30 100644 --- a/core/poller/config.go +++ b/core/poller/config.go @@ -1,13 +1,5 @@ package poller -/* - I consider this file the pinacle example of how to allow a Go application to be configured from a file. - You can put your configuration into any file format: XML, YAML, JSON, TOML, and you can override any - struct member using an environment variable. The Duration type is also supported. All of the Config{} - and Duration{} types and methods are reusable in other projects. Just adjust the data in the struct to - meet your app's needs. See the New() procedure and Start() method in start.go for example usage. -*/ - import ( "os" "path" @@ -44,13 +36,14 @@ type Flags struct { // Metrics is a type shared by the exporting and reporting packages. type Metrics struct { - TS time.Time - unifi.Sites - unifi.IDSList - unifi.Clients - *unifi.Devices + TS time.Time + Sites []*unifi.Site + IDSList []*unifi.IDS + Events []*unifi.Event + Clients []*unifi.Client SitesDPI []*unifi.DPITable ClientsDPI []*unifi.DPITable + *unifi.Devices } // Config represents the core library input data. diff --git a/core/poller/dumper.go b/core/poller/dumper.go index c78edabb..9b1b962c 100644 --- a/core/poller/dumper.go +++ b/core/poller/dumper.go @@ -9,25 +9,23 @@ import ( // DumpJSONPayload prints raw json from the UniFi Controller. This is currently // tied into the -j CLI arg, and is probably not very useful outside that context. func (u *UnifiPoller) DumpJSONPayload() (err error) { - u.Config.Quiet = true split := strings.SplitN(u.Flags.DumpJSON, " ", 2) filter := &Filter{Kind: split[0]} + // Allows you to grab a controller other than 0 from config. if split2 := strings.Split(filter.Kind, ":"); len(split2) > 1 { filter.Kind = split2[0] filter.Unit, _ = strconv.Atoi(split2[1]) } + // Used with "other" if len(split) > 1 { filter.Path = split[1] } + // As of now we only have one input plugin, so target that [0]. m, err := inputs[0].RawMetrics(filter) - if err != nil { - return err - } - fmt.Println(string(m)) - return nil + return err } diff --git a/core/poller/go.mod b/core/poller/go.mod index 835c13fd..90fd03bb 100644 --- a/core/poller/go.mod +++ b/core/poller/go.mod @@ -9,7 +9,7 @@ require ( github.com/prometheus/common v0.10.0 github.com/prometheus/procfs v0.1.1 // indirect github.com/spf13/pflag v1.0.5 - github.com/unifi-poller/unifi v0.0.4 + github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5 golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect golift.io/cnfg v0.0.5 diff --git a/core/poller/go.sum b/core/poller/go.sum index 888fda0c..53a971b8 100644 --- a/core/poller/go.sum +++ b/core/poller/go.sum @@ -62,6 +62,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0 h1:vrDKnkGzuGvhNAL56c7DBz29ZL+KxnoR0x7enabFceM= @@ -106,6 +108,8 @@ github.com/unifi-poller/unifi v0.0.3 h1:6pmjW7MuEEDKKvYoxjL3EZlaLOgmhYyxJBAg4X7G github.com/unifi-poller/unifi v0.0.3/go.mod h1:DagVD/I+VMnVUHmTT4Fi76lPI+DHbuMwwtMIzanwMxM= github.com/unifi-poller/unifi v0.0.4 h1:NDTxHTdF0MAt1y1RU8J+MSqdYlO0CEIqlrktcj3y/og= github.com/unifi-poller/unifi v0.0.4/go.mod h1:bTUtctrf56aapjKH+L+98eThBaVFbQXw5iNGZI0g/+E= +github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5 h1:DI1Dtq+2CY1t0Woesz7CRkbNrUT5GSX0h8mDsP3pgcw= +github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/core/poller/inputs.go b/core/poller/inputs.go index 12409ec9..793f1e66 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -1,7 +1,6 @@ package poller import ( - "fmt" "strings" "sync" @@ -16,9 +15,8 @@ var ( // Input plugins must implement this interface. type Input interface { - Initialize(Logger) error // Called once on startup to initialize the plugin. - Metrics() (*Metrics, bool, error) // Called every time new metrics are requested. - MetricsFrom(*Filter) (*Metrics, bool, error) // Called every time new metrics are requested. + Initialize(Logger) error // Called once on startup to initialize the plugin. + Metrics(*Filter) (*Metrics, error) // Called every time new metrics are requested. RawMetrics(*Filter) ([]byte, error) } @@ -34,10 +32,12 @@ type Filter struct { Type string Term string Name string + Call string Tags string Role string Kind string Path string + Text string Area int Item int Unit int @@ -79,75 +79,43 @@ func (u *UnifiPoller) InitializeInputs() error { return nil } -// Metrics aggregates all the measurements from all configured inputs and returns them. -func (u *UnifiPoller) Metrics() (*Metrics, bool, error) { - errs := []string{} +// Metrics aggregates all the measurements from filtered inputs and returns them. +// Passing a null filter returns everything! +func (u *UnifiPoller) Metrics(filter *Filter) (*Metrics, error) { metrics := &Metrics{} - ok := false - - for _, input := range inputs { - m, _, err := input.Metrics() - if err != nil { - errs = append(errs, err.Error()) - } - - if m == nil { - continue - } - - ok = true - metrics = AppendMetrics(metrics, m) - } - - var err error - - if len(errs) > 0 { - err = fmt.Errorf(strings.Join(errs, ", ")) // nolint: goerr113 - } - - return metrics, ok, err -} - -// MetricsFrom aggregates all the measurements from filtered inputs and returns them. -func (u *UnifiPoller) MetricsFrom(filter *Filter) (*Metrics, bool, error) { - errs := []string{} - metrics := &Metrics{} - ok := false for _, input := range inputs { if filter != nil && !strings.EqualFold(input.Name, filter.Name) { continue } - m, _, err := input.MetricsFrom(filter) + m, err := input.Metrics(filter) if err != nil { - errs = append(errs, err.Error()) + return metrics, err } - if m == nil { - continue - } - - ok = true metrics = AppendMetrics(metrics, m) } - var err error - - if len(errs) > 0 { - err = fmt.Errorf(strings.Join(errs, ", ")) // nolint: goerr113 - } - - return metrics, ok, err + return metrics, nil } -// AppendMetrics combined the metrics from two sources. +// AppendMetrics combines the metrics from two sources. func AppendMetrics(existing *Metrics, m *Metrics) *Metrics { + if existing == nil { + return m + } + + if m == nil { + return existing + } + existing.SitesDPI = append(existing.SitesDPI, m.SitesDPI...) existing.Sites = append(existing.Sites, m.Sites...) existing.ClientsDPI = append(existing.ClientsDPI, m.ClientsDPI...) existing.Clients = append(existing.Clients, m.Clients...) existing.IDSList = append(existing.IDSList, m.IDSList...) + existing.Events = append(existing.Events, m.Events...) if m.Devices == nil { return existing diff --git a/core/poller/outputs.go b/core/poller/outputs.go index 8cdb230e..62fc482c 100644 --- a/core/poller/outputs.go +++ b/core/poller/outputs.go @@ -16,8 +16,7 @@ var ( // Collect is passed into output packages so they may collect metrics to output. // Output packages must implement this interface. type Collect interface { - Metrics() (*Metrics, bool, error) - MetricsFrom(*Filter) (*Metrics, bool, error) + Metrics(*Filter) (*Metrics, error) Logger } diff --git a/core/poller/start.go b/core/poller/start.go index 515aa2dc..6078ce94 100644 --- a/core/poller/start.go +++ b/core/poller/start.go @@ -69,6 +69,7 @@ func (f *Flags) Parse(args []string) { // 3. Start a web server and wait for Prometheus to poll the application for metrics. func (u *UnifiPoller) Run() error { if u.Flags.DumpJSON != "" { + u.Config.Quiet = true if err := u.InitializeInputs(); err != nil { return err } From 15fd679f557f3ef7323839516c89ce66b62e1c0d Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 21 Jun 2020 01:40:19 -0700 Subject: [PATCH 2/8] Fixes --- core/poller/config.go | 4 ++++ core/poller/go.mod | 2 +- core/poller/go.sum | 2 ++ core/poller/inputs.go | 22 ++++++++++++++++++++++ core/poller/outputs.go | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/poller/config.go b/core/poller/config.go index c4f49e30..e4d9ea4e 100644 --- a/core/poller/config.go +++ b/core/poller/config.go @@ -46,6 +46,10 @@ type Metrics struct { *unifi.Devices } +type Events struct { + Logs []interface{} +} + // Config represents the core library input data. type Config struct { *Poller `json:"poller" toml:"poller" xml:"poller" yaml:"poller"` diff --git a/core/poller/go.mod b/core/poller/go.mod index 90fd03bb..087a3178 100644 --- a/core/poller/go.mod +++ b/core/poller/go.mod @@ -9,7 +9,7 @@ require ( github.com/prometheus/common v0.10.0 github.com/prometheus/procfs v0.1.1 // indirect github.com/spf13/pflag v1.0.5 - github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5 + github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect golift.io/cnfg v0.0.5 diff --git a/core/poller/go.sum b/core/poller/go.sum index 53a971b8..0a3670f9 100644 --- a/core/poller/go.sum +++ b/core/poller/go.sum @@ -110,6 +110,8 @@ github.com/unifi-poller/unifi v0.0.4 h1:NDTxHTdF0MAt1y1RU8J+MSqdYlO0CEIqlrktcj3y github.com/unifi-poller/unifi v0.0.4/go.mod h1:bTUtctrf56aapjKH+L+98eThBaVFbQXw5iNGZI0g/+E= github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5 h1:DI1Dtq+2CY1t0Woesz7CRkbNrUT5GSX0h8mDsP3pgcw= github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8= +github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd h1:jrwuiY1AdoPi+b+R8zjt/e8h8ZqULNB9izcyQnf3pSw= +github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/core/poller/inputs.go b/core/poller/inputs.go index 793f1e66..422d18e6 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -17,6 +17,7 @@ var ( type Input interface { Initialize(Logger) error // Called once on startup to initialize the plugin. Metrics(*Filter) (*Metrics, error) // Called every time new metrics are requested. + Events(*Filter) (*Events, error) // This is new. RawMetrics(*Filter) ([]byte, error) } @@ -79,6 +80,27 @@ func (u *UnifiPoller) InitializeInputs() error { return nil } +// Events aggregates log messages (events) from one or more sources. +func (u *UnifiPoller) Events(filter *Filter) (*Events, error) { + events := Events{} + + for _, input := range inputs { + if filter != nil && !strings.EqualFold(input.Name, filter.Name) { + continue + } + + e, err := input.Events(filter) + if err != nil { + return &events, err + } + + // Logs is the only member to extend at this time. + events.Logs = append(events.Logs, e) + } + + return &events, nil +} + // Metrics aggregates all the measurements from filtered inputs and returns them. // Passing a null filter returns everything! func (u *UnifiPoller) Metrics(filter *Filter) (*Metrics, error) { diff --git a/core/poller/outputs.go b/core/poller/outputs.go index 62fc482c..ad90b9ad 100644 --- a/core/poller/outputs.go +++ b/core/poller/outputs.go @@ -17,6 +17,7 @@ var ( // Output packages must implement this interface. type Collect interface { Metrics(*Filter) (*Metrics, error) + Events(*Filter) (*Events, error) Logger } From 2010789dac2f0d58d90aab474e5631818f3a9906 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 21 Jun 2020 02:18:16 -0700 Subject: [PATCH 3/8] Add more filter types --- core/poller/inputs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/poller/inputs.go b/core/poller/inputs.go index 422d18e6..c730a78f 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -3,6 +3,7 @@ package poller import ( "strings" "sync" + "time" "github.com/unifi-poller/unifi" ) @@ -50,6 +51,10 @@ type Filter struct { True bool Done bool Stop bool + Time time.Time + From time.Time + When time.Time + Dur time.Duration } // NewInput creates a metric input. This should be called by input plugins From 1fde085b53495a10287721c4f131409dabdd24f1 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 21 Jun 2020 02:51:43 -0700 Subject: [PATCH 4/8] fix bug --- core/poller/inputs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/poller/inputs.go b/core/poller/inputs.go index c730a78f..c94d9c43 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -90,7 +90,7 @@ func (u *UnifiPoller) Events(filter *Filter) (*Events, error) { events := Events{} for _, input := range inputs { - if filter != nil && !strings.EqualFold(input.Name, filter.Name) { + if filter != nil && filter.Name != "" && !strings.EqualFold(input.Name, filter.Name) { continue } @@ -112,7 +112,7 @@ func (u *UnifiPoller) Metrics(filter *Filter) (*Metrics, error) { metrics := &Metrics{} for _, input := range inputs { - if filter != nil && !strings.EqualFold(input.Name, filter.Name) { + if filter != nil && filter.Name != "" && !strings.EqualFold(input.Name, filter.Name) { continue } From 63ad9d9fd4bfc78b40f27e5304c05bc36f224be8 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 21 Jun 2020 03:12:55 -0700 Subject: [PATCH 5/8] minor adjustments --- core/poller/inputs.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/core/poller/inputs.go b/core/poller/inputs.go index c94d9c43..e45ed9ab 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -34,26 +34,14 @@ type Filter struct { Type string Term string Name string - Call string - Tags string Role string Kind string Path string Text string - Area int - Item int Unit int - Sign int64 - Mass int64 - Rate float64 - Cost float64 - Free bool - True bool - Done bool - Stop bool + Pass bool + Skip bool Time time.Time - From time.Time - When time.Time Dur time.Duration } @@ -90,7 +78,9 @@ func (u *UnifiPoller) Events(filter *Filter) (*Events, error) { events := Events{} for _, input := range inputs { - if filter != nil && filter.Name != "" && !strings.EqualFold(input.Name, filter.Name) { + if filter != nil && + filter.Name != "" && + !strings.EqualFold(input.Name, filter.Name) { continue } @@ -112,7 +102,9 @@ func (u *UnifiPoller) Metrics(filter *Filter) (*Metrics, error) { metrics := &Metrics{} for _, input := range inputs { - if filter != nil && filter.Name != "" && !strings.EqualFold(input.Name, filter.Name) { + if filter != nil && + filter.Name != "" && + !strings.EqualFold(input.Name, filter.Name) { continue } From 1ded2fdf8943ddf9fbfd7c6e8999f56b5ab3a0fc Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 21 Jun 2020 03:37:17 -0700 Subject: [PATCH 6/8] return a []interface of events. --- core/poller/config.go | 2 -- core/poller/inputs.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/core/poller/config.go b/core/poller/config.go index e4d9ea4e..9d0a37eb 100644 --- a/core/poller/config.go +++ b/core/poller/config.go @@ -38,8 +38,6 @@ type Flags struct { type Metrics struct { TS time.Time Sites []*unifi.Site - IDSList []*unifi.IDS - Events []*unifi.Event Clients []*unifi.Client SitesDPI []*unifi.DPITable ClientsDPI []*unifi.DPITable diff --git a/core/poller/inputs.go b/core/poller/inputs.go index e45ed9ab..c06333b5 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -133,8 +133,6 @@ func AppendMetrics(existing *Metrics, m *Metrics) *Metrics { existing.Sites = append(existing.Sites, m.Sites...) existing.ClientsDPI = append(existing.ClientsDPI, m.ClientsDPI...) existing.Clients = append(existing.Clients, m.Clients...) - existing.IDSList = append(existing.IDSList, m.IDSList...) - existing.Events = append(existing.Events, m.Events...) if m.Devices == nil { return existing From 05286b9cfa16a80c6eaaf3e80b1bf7948fddf114 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 21 Jun 2020 14:39:20 -0700 Subject: [PATCH 7/8] fully generic --- core/poller/config.go | 11 +++++------ core/poller/go.mod | 1 - core/poller/go.sum | 37 ------------------------------------- core/poller/inputs.go | 16 +--------------- 4 files changed, 6 insertions(+), 59 deletions(-) diff --git a/core/poller/config.go b/core/poller/config.go index 9d0a37eb..0f13cb8e 100644 --- a/core/poller/config.go +++ b/core/poller/config.go @@ -8,7 +8,6 @@ import ( "time" "github.com/spf13/pflag" - "github.com/unifi-poller/unifi" "golift.io/cnfg" "golift.io/cnfg/cnfgfile" ) @@ -37,11 +36,11 @@ type Flags struct { // Metrics is a type shared by the exporting and reporting packages. type Metrics struct { TS time.Time - Sites []*unifi.Site - Clients []*unifi.Client - SitesDPI []*unifi.DPITable - ClientsDPI []*unifi.DPITable - *unifi.Devices + Sites []interface{} + Clients []interface{} + SitesDPI []interface{} + ClientsDPI []interface{} + Devices []interface{} } type Events struct { diff --git a/core/poller/go.mod b/core/poller/go.mod index 087a3178..494b55a8 100644 --- a/core/poller/go.mod +++ b/core/poller/go.mod @@ -9,7 +9,6 @@ require ( github.com/prometheus/common v0.10.0 github.com/prometheus/procfs v0.1.1 // indirect github.com/spf13/pflag v1.0.5 - github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect golift.io/cnfg v0.0.5 diff --git a/core/poller/go.sum b/core/poller/go.sum index 0a3670f9..becf9b08 100644 --- a/core/poller/go.sum +++ b/core/poller/go.sum @@ -6,7 +6,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -28,10 +27,7 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -62,34 +58,22 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0 h1:vrDKnkGzuGvhNAL56c7DBz29ZL+KxnoR0x7enabFceM= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.4.0 h1:YVIb/fVcOTMSqtqZWSKnHpSLBxu8DKgxq8z6RuBZwqI= -github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.6.0 h1:YVPodQOcK15POxhgARIvnDRVpLcuK8mglnMrWfyrw6A= github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY= -github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= -github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= -github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.1.1 h1:/ZKcW+ixpq2dOl4yeH4qvACNXnkiDCp5e/F5Tq07X7o= github.com/prometheus/procfs v0.1.1/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= @@ -102,16 +86,6 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/unifi-poller/unifi v0.0.2 h1:FRa6G+VcxOdvy0/u/QLCHGCRYF6EDcxVYij0dDRCKxg= -github.com/unifi-poller/unifi v0.0.2/go.mod h1:DagVD/I+VMnVUHmTT4Fi76lPI+DHbuMwwtMIzanwMxM= -github.com/unifi-poller/unifi v0.0.3 h1:6pmjW7MuEEDKKvYoxjL3EZlaLOgmhYyxJBAg4X7GliI= -github.com/unifi-poller/unifi v0.0.3/go.mod h1:DagVD/I+VMnVUHmTT4Fi76lPI+DHbuMwwtMIzanwMxM= -github.com/unifi-poller/unifi v0.0.4 h1:NDTxHTdF0MAt1y1RU8J+MSqdYlO0CEIqlrktcj3y/og= -github.com/unifi-poller/unifi v0.0.4/go.mod h1:bTUtctrf56aapjKH+L+98eThBaVFbQXw5iNGZI0g/+E= -github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5 h1:DI1Dtq+2CY1t0Woesz7CRkbNrUT5GSX0h8mDsP3pgcw= -github.com/unifi-poller/unifi v0.0.5-0.20200619092006-d24c776a42f5/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8= -github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd h1:jrwuiY1AdoPi+b+R8zjt/e8h8ZqULNB9izcyQnf3pSw= -github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -124,9 +98,6 @@ golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -140,10 +111,6 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200610111108-226ff32320da h1:bGb80FudwxpeucJUjPYJXuJ8Hk91vNtfvrymzwiei38= @@ -170,7 +137,6 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA= @@ -179,12 +145,9 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/core/poller/inputs.go b/core/poller/inputs.go index c06333b5..b992db0d 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -4,8 +4,6 @@ import ( "strings" "sync" "time" - - "github.com/unifi-poller/unifi" ) var ( @@ -133,19 +131,7 @@ func AppendMetrics(existing *Metrics, m *Metrics) *Metrics { existing.Sites = append(existing.Sites, m.Sites...) existing.ClientsDPI = append(existing.ClientsDPI, m.ClientsDPI...) existing.Clients = append(existing.Clients, m.Clients...) - - if m.Devices == nil { - return existing - } - - if existing.Devices == nil { - existing.Devices = &unifi.Devices{} - } - - existing.UAPs = append(existing.UAPs, m.UAPs...) - existing.USGs = append(existing.USGs, m.USGs...) - existing.USWs = append(existing.USWs, m.USWs...) - existing.UDMs = append(existing.UDMs, m.UDMs...) + existing.Devices = append(existing.Devices, m.Devices...) return existing } From 7cecc18110e5022856b77e22a4794a6246a447de Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Sun, 21 Jun 2020 21:18:12 -0700 Subject: [PATCH 8/8] bug --- core/poller/README.md | 21 ++++++++++++++++++++- core/poller/dumper.go | 4 ++-- core/poller/inputs.go | 2 +- core/poller/start.go | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/core/poller/README.md b/core/poller/README.md index 7649aa1e..c658a12f 100644 --- a/core/poller/README.md +++ b/core/poller/README.md @@ -4,4 +4,23 @@ This module ties the inputs together with the outputs. -Aggregates metrics on request. +Aggregates metrics on request. Provides CLI app and args parsing. + + +# Ideal + +This library has no notion of "UniFi" or controllers, or Influx, or Prometheus. +This library simply provides an input interface and an output interface. +Each interface uses an `[]interface{}` type, so any type of data can be used. +That is to say, you could write input and output plugins that work with, say, +Cisco gear, or any other network (or even non-network) data. The existing plugins +should provide ample example of how to use this library, but at some point the +godoc will improve. + +# Features + +- Automatically unmarshal's plugin config structs from config file and/or env variables. +- Initializes all "imported" plugins on startup. +- Provides input plugins a Logger, requires an interface for Metrics and Events retrieval. +- Provides Output plugins an interface to retrieve Metrics and Events, and a Logger. +- Provides automatic aggregation of Metrics and Events from multiple sources. diff --git a/core/poller/dumper.go b/core/poller/dumper.go index 9b1b962c..9533a301 100644 --- a/core/poller/dumper.go +++ b/core/poller/dumper.go @@ -6,9 +6,9 @@ import ( "strings" ) -// DumpJSONPayload prints raw json from the UniFi Controller. This is currently +// PrintRawMetrics prints raw json from the UniFi Controller. This is currently // tied into the -j CLI arg, and is probably not very useful outside that context. -func (u *UnifiPoller) DumpJSONPayload() (err error) { +func (u *UnifiPoller) PrintRawMetrics() (err error) { split := strings.SplitN(u.Flags.DumpJSON, " ", 2) filter := &Filter{Kind: split[0]} diff --git a/core/poller/inputs.go b/core/poller/inputs.go index b992db0d..85753d28 100644 --- a/core/poller/inputs.go +++ b/core/poller/inputs.go @@ -88,7 +88,7 @@ func (u *UnifiPoller) Events(filter *Filter) (*Events, error) { } // Logs is the only member to extend at this time. - events.Logs = append(events.Logs, e) + events.Logs = append(events.Logs, e.Logs...) } return &events, nil diff --git a/core/poller/start.go b/core/poller/start.go index 6078ce94..3f20d687 100644 --- a/core/poller/start.go +++ b/core/poller/start.go @@ -74,7 +74,7 @@ func (u *UnifiPoller) Run() error { return err } - return u.DumpJSONPayload() + return u.PrintRawMetrics() } if u.Debug {