Remove events from metrics
This commit is contained in:
parent
bc23ac89c8
commit
9ab151bc1a
|
|
@ -105,28 +105,6 @@ func (u *InputUnifi) pollController(c *Controller, filter *poller.Filter) (*poll
|
|||
}
|
||||
}
|
||||
|
||||
if !filter.Skip && c.SaveEvents != nil && *c.SaveEvents {
|
||||
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 {
|
||||
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.
|
||||
if m.Clients, err = c.Unifi.GetClients(m.Sites); err != nil {
|
||||
return nil, errors.Wrapf(err, "unifi.GetClients(%s)", c.URL)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ go 1.14
|
|||
|
||||
require (
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/unifi-poller/poller v0.0.8-0.20200621103717-5f3d60890ed6
|
||||
github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10
|
||||
github.com/unifi-poller/unifi v0.0.5-0.20200621075746-253ccae7e106
|
||||
)
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ github.com/unifi-poller/poller v0.0.8-0.20200621101255-6d0d0b288ece h1:EsyR6cKuw
|
|||
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/poller v0.0.8-0.20200621110949-33f1a1454d10 h1:1rGP4ISFpBj9xjJDXNak7EdaQtyoy3MwMZzo2+W1PLo=
|
||||
github.com/unifi-poller/poller v0.0.8-0.20200621110949-33f1a1454d10/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=
|
||||
|
|
|
|||
|
|
@ -77,9 +77,8 @@ func (u *InputUnifi) logController(c *Controller) {
|
|||
}
|
||||
|
||||
// Events allows you to pull only events (and IDS) from the UniFi Controller.
|
||||
// This does not respect HashPII, but it may in the future!
|
||||
// This does not fully respect HashPII, but it may in the future!
|
||||
// Use Filter.Dur to set a search duration into the past; 1 minute default.
|
||||
// Set Filter.Skip to true to disable IDS collection.
|
||||
func (u *InputUnifi) Events(filter *poller.Filter) (*poller.Events, error) {
|
||||
if u.Disable {
|
||||
return nil, nil
|
||||
|
|
@ -88,32 +87,32 @@ func (u *InputUnifi) Events(filter *poller.Filter) (*poller.Events, error) {
|
|||
events := &poller.Events{}
|
||||
|
||||
for _, c := range u.Controllers {
|
||||
if filter != nil && filter.Path != "" &&
|
||||
!strings.EqualFold(c.URL, filter.Path) {
|
||||
// continue only if we have a filter path and it doesn't match.
|
||||
continue
|
||||
}
|
||||
|
||||
if filter == nil || filter.Dur == 0 {
|
||||
filter = &poller.Filter{Dur: time.Minute}
|
||||
}
|
||||
|
||||
if filter.Path != "" && !strings.EqualFold(c.URL, filter.Path) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Get the sites we care about.
|
||||
sites, err := u.getFilteredSites(c)
|
||||
if err != nil {
|
||||
return events, errors.Wrap(err, "unifi.GetSites()")
|
||||
}
|
||||
|
||||
e, err := c.Unifi.GetEvents(sites, time.Now().Add(-filter.Dur))
|
||||
if err != nil {
|
||||
return events, errors.Wrap(err, "unifi.GetEvents()")
|
||||
if *c.SaveEvents {
|
||||
e, err := c.Unifi.GetEvents(sites, time.Now().Add(-filter.Dur))
|
||||
if err != nil {
|
||||
return events, errors.Wrap(err, "unifi.GetEvents()")
|
||||
}
|
||||
|
||||
for _, l := range e {
|
||||
events.Logs = append(events.Logs, redactEvent(l, c.HashPII))
|
||||
}
|
||||
}
|
||||
|
||||
for _, l := range e {
|
||||
events.Logs = append(events.Logs, l)
|
||||
}
|
||||
|
||||
if !filter.Skip {
|
||||
if *c.SaveIDS {
|
||||
i, err := c.Unifi.GetIDS(sites, time.Now().Add(-filter.Dur))
|
||||
if err != nil {
|
||||
return events, errors.Wrap(err, "unifi.GetIDS()")
|
||||
|
|
@ -130,7 +129,6 @@ func (u *InputUnifi) Events(filter *poller.Filter) (*poller.Events, error) {
|
|||
|
||||
// Metrics grabs all the measurements from a UniFi controller and returns them.
|
||||
// Set Filter.Path to a controller URL for a specific controller (or get them all).
|
||||
// Set Filter.Skip to true to Skip Events and IDS collection (Prometheus does this).
|
||||
func (u *InputUnifi) Metrics(filter *poller.Filter) (*poller.Metrics, error) {
|
||||
if u.Disable {
|
||||
return nil, nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue