skip older events

This commit is contained in:
davidnewhall2 2020-06-22 00:15:47 -07:00
parent 7587a390fb
commit 4d70730b6b
2 changed files with 14 additions and 2 deletions

View File

@ -1,11 +1,19 @@
package influxunifi
import (
"time"
"github.com/unifi-poller/unifi"
)
// batchIDS generates intrusion detection datapoints for InfluxDB.
func (u *InfluxUnifi) batchIDS(r report, i *unifi.IDS) {
if time.Since(i.Datetime) > u.Interval.Duration+time.Second {
return // The event is older than our interval, ignore it.
}
r.addIDS()
fields := map[string]interface{}{
"dest_port": i.DestPort,
"src_port": i.SrcPort,
@ -56,6 +64,12 @@ func (u *InfluxUnifi) batchIDS(r report, i *unifi.IDS) {
// batchEvents generates events from UniFi for InfluxDB.
func (u *InfluxUnifi) batchEvent(r report, i *unifi.Event) { // nolint: funlen
if time.Since(i.Datetime) > u.Interval.Duration+time.Second {
return // The event is older than our interval, ignore it.
}
r.addEvent()
fields := map[string]interface{}{
"msg": i.Msg, // contains user[] or guest[] or admin[]
"duration": i.Duration.Val, // probably microseconds?

View File

@ -264,10 +264,8 @@ func (u *InfluxUnifi) switchExport(r report, v interface{}) {
case *unifi.Client:
u.batchClient(r, v)
case *unifi.Event:
r.addEvent()
u.batchEvent(r, v)
case *unifi.IDS:
r.addIDS()
u.batchIDS(r, v)
default:
u.Collector.LogErrorf("invalid export type: %T", v)