From b93b76e1debf03d728b39c25f43e9f66ca02aeb1 Mon Sep 17 00:00:00 2001 From: davidnewhall2 Date: Wed, 24 Jun 2020 14:20:35 -0700 Subject: [PATCH] store start time in struct --- integrations/lokiunifi/loki.go | 26 ++++++++++++-------------- integrations/lokiunifi/report.go | 1 + 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/integrations/lokiunifi/loki.go b/integrations/lokiunifi/loki.go index 1afbcf61..499834cf 100644 --- a/integrations/lokiunifi/loki.go +++ b/integrations/lokiunifi/loki.go @@ -107,12 +107,20 @@ func (l *Loki) pollController(start time.Time) error { return errors.Wrap(err, "event fetch for Loki failed") } - return l.ReportEvents(l.NewReport(events), start) + report := &Report{ + Events: events, + Start: start, + Logger: l.Collect, + Loki: l.client, + Last: l.last, + } + + return l.ReportEvents(report) } // ReportEvents should be easy to test. // Reports events to Loki, updates last check time, and prints a log message. -func (l *Loki) ReportEvents(r *Report, start time.Time) error { +func (l *Loki) ReportEvents(r *Report) error { // Sometimes it gets stuck on old messages. This gets it past that. if time.Since(l.last) > 4*l.Interval.Duration { l.last = time.Now().Add(-4 * l.Interval.Duration) @@ -122,19 +130,9 @@ func (l *Loki) ReportEvents(r *Report, start time.Time) error { return errors.Wrap(err, "sending to Loki failed") } - l.last = start + l.last = r.Start l.Logf("Events sent to Loki. Events: %d, IDS: %d, Dur: %v", r.Eve, r.IDS, - time.Since(start).Round(time.Millisecond)) + time.Since(l.last).Round(time.Millisecond)) return nil } - -// NewReport creates a new [interval] report from the input config data. -func (l *Loki) NewReport(events *poller.Events) *Report { - return &Report{ - Events: events, - Logger: l.Collect, - Loki: l.client, - Last: l.last, - } -} diff --git a/integrations/lokiunifi/report.go b/integrations/lokiunifi/report.go index cc917e74..9d8a655a 100644 --- a/integrations/lokiunifi/report.go +++ b/integrations/lokiunifi/report.go @@ -25,6 +25,7 @@ type Logs struct { type Report struct { Eve int // Total count of Events. IDS int // Total count of IDS/IPS Events. + Start time.Time Last time.Time Loki *Client Events *poller.Events