minor fixes

This commit is contained in:
davidnewhall2 2020-06-25 03:33:58 -07:00
parent 975a9afd85
commit ee90410d8f
2 changed files with 7 additions and 10 deletions

View File

@ -108,12 +108,11 @@ func (l *Loki) pollController(start time.Time) error {
}
report := &Report{
Events: events,
Start: start,
Logger: l.Collect,
Client: l.client,
Last: &l.last,
}
return report.Execute(4 * l.Interval.Duration) // nolint: gomnd
return report.Execute(events, 4*l.Interval.Duration) // nolint: gomnd
}

View File

@ -27,20 +27,18 @@ type Report struct {
Start time.Time
Last *time.Time
Client *Client
Events *poller.Events
LogStreams
poller.Logger
}
// ReportEvents should be easy to test.
// Reports events to Loki, updates last check time, and prints a log message.
func (r *Report) Execute(skipDur time.Duration) error {
// Execute processes events, reports events to Loki, updates last check time, and prints a log message.
func (r *Report) Execute(events *poller.Events, skipDur time.Duration) error {
// Sometimes it gets stuck on old messages. This gets it past that.
if time.Since(*r.Last) > skipDur {
*r.Last = time.Now().Add(-skipDur)
}
r.ProcessEventLogs() // Compile report.
r.ProcessEventLogs(events) // Compile report.
// Send report to Loki.
if err := r.Client.Post(r.LogStreams); err != nil {
@ -48,7 +46,7 @@ func (r *Report) Execute(skipDur time.Duration) error {
}
*r.Last = r.Start
r.Logf("Events sent to Loki. Events: %d, IDS: %d, Alarm: %d, Anomalies: %d, Dur: %v",
r.Logf("Events sent to Loki. Event: %d, IDS: %d, Alarm: %d, Anomaly: %d, Dur: %v",
r.Counts[typeEvent], r.Counts[typeIDS], r.Counts[typeAlarm], r.Counts[typeAnomaly],
time.Since(r.Start).Round(time.Millisecond))
@ -58,8 +56,8 @@ func (r *Report) Execute(skipDur time.Duration) error {
// ProcessEventLogs loops the event Logs, matches the interface
// type, calls the appropriate method for the data, and compiles the report.
// This runs once per interval, if there was no collection error.
func (r *Report) ProcessEventLogs() {
for _, e := range r.Events.Logs {
func (r *Report) ProcessEventLogs(events *poller.Events) {
for _, e := range events.Logs {
switch event := e.(type) {
case *unifi.IDS:
r.IDS(event)