store start time in struct
This commit is contained in:
		
							parent
							
								
									6a0cc0d2a6
								
							
						
					
					
						commit
						b93b76e1de
					
				| 
						 | 
					@ -107,12 +107,20 @@ func (l *Loki) pollController(start time.Time) error {
 | 
				
			||||||
		return errors.Wrap(err, "event fetch for Loki failed")
 | 
							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.
 | 
					// ReportEvents should be easy to test.
 | 
				
			||||||
// Reports events to Loki, updates last check time, and prints a log message.
 | 
					// 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.
 | 
						// Sometimes it gets stuck on old messages. This gets it past that.
 | 
				
			||||||
	if time.Since(l.last) > 4*l.Interval.Duration {
 | 
						if time.Since(l.last) > 4*l.Interval.Duration {
 | 
				
			||||||
		l.last = time.Now().Add(-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")
 | 
							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,
 | 
						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
 | 
						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,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,6 +25,7 @@ type Logs struct {
 | 
				
			||||||
type Report struct {
 | 
					type Report struct {
 | 
				
			||||||
	Eve    int // Total count of Events.
 | 
						Eve    int // Total count of Events.
 | 
				
			||||||
	IDS    int // Total count of IDS/IPS Events.
 | 
						IDS    int // Total count of IDS/IPS Events.
 | 
				
			||||||
 | 
						Start  time.Time
 | 
				
			||||||
	Last   time.Time
 | 
						Last   time.Time
 | 
				
			||||||
	Loki   *Client
 | 
						Loki   *Client
 | 
				
			||||||
	Events *poller.Events
 | 
						Events *poller.Events
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue