diff --git a/integrations/inputunifi/collector.go b/integrations/inputunifi/collector.go index a4326264..01daf0db 100644 --- a/integrations/inputunifi/collector.go +++ b/integrations/inputunifi/collector.go @@ -106,17 +106,25 @@ func (u *InputUnifi) pollController(c *Controller, filter *poller.Filter) (*poll } if !filter.Skip && c.SaveEvents != nil && *c.SaveEvents { - m.Events, err = c.Unifi.GetEvents(m.Sites, time.Now().Add(time.Minute)) + e, err := c.Unifi.GetEvents(m.Sites, time.Now().Add(time.Minute)) if err != nil { return nil, errors.Wrapf(err, "unifi.GetEvents(%s)", c.URL) } + + for _, l := range e { + m.Events = append(m.Events, redactEvent(l, c.HashPII)) + } } if !filter.Skip && c.SaveIDS != nil && *c.SaveIDS { - m.IDSList, err = c.Unifi.GetIDS(m.Sites, time.Now().Add(time.Minute)) + e, err := c.Unifi.GetIDS(m.Sites, time.Now().Add(time.Minute)) if err != nil { return nil, errors.Wrapf(err, "unifi.GetIDS(%s)", c.URL) } + + for _, l := range e { + m.Events = append(m.Events, l) + } } // Get all the points. @@ -134,7 +142,7 @@ func (u *InputUnifi) pollController(c *Controller, filter *poller.Filter) (*poll // 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 (u *InputUnifi) augmentMetrics(c *Controller, metrics *poller.Metrics) *poller.Metrics { // nolint: funlen +func (u *InputUnifi) augmentMetrics(c *Controller, metrics *poller.Metrics) *poller.Metrics { if metrics == nil || metrics.Devices == nil || metrics.Clients == nil { return metrics } @@ -162,18 +170,6 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *poller.Metrics) *pol devices[r.Mac] = r.Name } - if *c.HashPII { - for i := range metrics.Events { - // metrics.Events[i].Msg <-- not sure what to do here. - metrics.Events[i].DestIPGeo = unifi.IPGeo{} - metrics.Events[i].SourceIPGeo = unifi.IPGeo{} - metrics.Events[i].Host = RedactNamePII(metrics.Events[i].Host, c.HashPII) - metrics.Events[i].Hostname = RedactNamePII(metrics.Events[i].Hostname, c.HashPII) - metrics.Events[i].DstMAC = RedactMacPII(metrics.Events[i].DstMAC, c.HashPII) - metrics.Events[i].SrcMAC = RedactMacPII(metrics.Events[i].SrcMAC, c.HashPII) - } - } - // These come blank, so set them here. for i, client := range metrics.Clients { if devices[client.Mac] = client.Name; client.Name == "" { @@ -207,6 +203,24 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *poller.Metrics) *pol return metrics } +// redactEvent attempts to mask personally identying information from log messages. +// This currently misses the "msg" value entirely and leaks PII information. +func redactEvent(e *unifi.Event, hash *bool) *unifi.Event { + if !*hash { + return e + } + + // metrics.Events[i].Msg <-- not sure what to do here. + e.DestIPGeo = unifi.IPGeo{} + e.SourceIPGeo = unifi.IPGeo{} + e.Host = RedactNamePII(e.Host, hash) + e.Hostname = RedactNamePII(e.Hostname, hash) + e.DstMAC = RedactMacPII(e.DstMAC, hash) + e.SrcMAC = RedactMacPII(e.SrcMAC, hash) + + return e +} + // RedactNamePII converts a name string to an md5 hash (first 24 chars only). // Useful for maskiing out personally identifying information. func RedactNamePII(pii string, hash *bool) string { diff --git a/integrations/inputunifi/go.mod b/integrations/inputunifi/go.mod index 9fb672c5..fab5f989 100644 --- a/integrations/inputunifi/go.mod +++ b/integrations/inputunifi/go.mod @@ -4,6 +4,6 @@ go 1.14 require ( github.com/pkg/errors v0.9.1 - github.com/unifi-poller/poller v0.0.8-0.20200621101255-6d0d0b288ece + github.com/unifi-poller/poller v0.0.8-0.20200621103717-5f3d60890ed6 github.com/unifi-poller/unifi v0.0.5-0.20200621075746-253ccae7e106 ) diff --git a/integrations/inputunifi/go.sum b/integrations/inputunifi/go.sum index c4b4155f..90193dec 100644 --- a/integrations/inputunifi/go.sum +++ b/integrations/inputunifi/go.sum @@ -94,6 +94,8 @@ github.com/unifi-poller/poller v0.0.8-0.20200621091816-fd5c7abd9f4b h1:AJKt/ZIDt github.com/unifi-poller/poller v0.0.8-0.20200621091816-fd5c7abd9f4b/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4= github.com/unifi-poller/poller v0.0.8-0.20200621101255-6d0d0b288ece h1:EsyR6cKuwAKzddS4gsKDugfN+OEHCm7bhNOvEfBCWWA= github.com/unifi-poller/poller v0.0.8-0.20200621101255-6d0d0b288ece/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4= +github.com/unifi-poller/poller v0.0.8-0.20200621103717-5f3d60890ed6 h1:V19WgXwjXxGY75Mn8Hc5Whl3+BC71YSGatRvKVRh9pA= +github.com/unifi-poller/poller v0.0.8-0.20200621103717-5f3d60890ed6/go.mod h1:+Ppksi2wBCrByJke0B0lTutxFtKfv1zx6L1haALBrN4= github.com/unifi-poller/unifi v0.0.5-0.20200620103801-b927287ea1cd/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8= github.com/unifi-poller/unifi v0.0.5-0.20200621075746-253ccae7e106 h1:eKErSqWD656pLSWgxFwhDhHe/zfAXrm7F39Zn4R+si8= github.com/unifi-poller/unifi v0.0.5-0.20200621075746-253ccae7e106/go.mod h1:L1kMRH2buZhB31vZnRC1im7Tk/4uD3ET4biwl2faYy8=