break up method

This commit is contained in:
davidnewhall2 2020-06-21 18:34:32 -07:00
parent 90bebbf165
commit 3c58f883f9
1 changed files with 34 additions and 28 deletions

View File

@ -125,7 +125,6 @@ func (u *InputUnifi) pollController(c *Controller) (*poller.Metrics, error) {
m := &Metrics{TS: time.Now()} // At this point, it's the Current Check. m := &Metrics{TS: time.Now()} // At this point, it's the Current Check.
// Get the sites we care about. // Get the sites we care about.
if m.Sites, err = u.getFilteredSites(c); err != nil { if m.Sites, err = u.getFilteredSites(c); err != nil {
return nil, errors.Wrap(err, "unifi.GetSites()") return nil, errors.Wrap(err, "unifi.GetSites()")
} }
@ -160,33 +159,7 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *Metrics) *poller.Met
return nil return nil
} }
m := &poller.Metrics{TS: metrics.TS} m, devices, bssdIDs := extractDevices(metrics)
devices := make(map[string]string)
bssdIDs := make(map[string]string)
for _, r := range metrics.Devices.UAPs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
for _, v := range r.VapTable {
bssdIDs[v.Bssid] = fmt.Sprintf("%s %s %s:", r.Name, v.Radio, v.RadioName)
}
}
for _, r := range metrics.Devices.USGs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
}
for _, r := range metrics.Devices.USWs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
}
for _, r := range metrics.Devices.UDMs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
}
// These come blank, so set them here. // These come blank, so set them here.
for _, client := range metrics.Clients { for _, client := range metrics.Clients {
@ -229,6 +202,39 @@ func (u *InputUnifi) augmentMetrics(c *Controller, metrics *Metrics) *poller.Met
return m return m
} }
// this is a helper function for augmentMetrics.
func extractDevices(metrics *Metrics) (*poller.Metrics, map[string]string, map[string]string) {
m := &poller.Metrics{TS: metrics.TS}
devices := make(map[string]string)
bssdIDs := make(map[string]string)
for _, r := range metrics.Devices.UAPs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
for _, v := range r.VapTable {
bssdIDs[v.Bssid] = fmt.Sprintf("%s %s %s:", r.Name, v.Radio, v.RadioName)
}
}
for _, r := range metrics.Devices.USGs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
}
for _, r := range metrics.Devices.USWs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
}
for _, r := range metrics.Devices.UDMs {
devices[r.Mac] = r.Name
m.Devices = append(m.Devices, r)
}
return m, devices, bssdIDs
}
// redactEvent attempts to mask personally identying information from log messages. // redactEvent attempts to mask personally identying information from log messages.
// This currently misses the "msg" value entirely and leaks PII information. // This currently misses the "msg" value entirely and leaks PII information.
func redactEvent(e *unifi.Event, hash *bool) *unifi.Event { func redactEvent(e *unifi.Event, hash *bool) *unifi.Event {