trigger.go 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package leakybucket
  2. import (
  3. "time"
  4. "github.com/crowdsecurity/crowdsec/pkg/types"
  5. log "github.com/sirupsen/logrus"
  6. )
  7. type Trigger struct {
  8. DumbProcessor
  9. }
  10. func (t *Trigger) OnBucketPour(b *BucketFactory) func(types.Event, *Leaky) *types.Event {
  11. // Pour makes the bucket overflow all the time
  12. // TriggerPour unconditionnaly overflows
  13. return func(msg types.Event, l *Leaky) *types.Event {
  14. if l.Mode == TIMEMACHINE {
  15. var d time.Time
  16. err := d.UnmarshalText([]byte(msg.MarshaledTime))
  17. if err != nil {
  18. log.Warningf("Failed unmarshaling event time (%s) : %v", msg.MarshaledTime, err)
  19. d = time.Now().UTC()
  20. }
  21. l.logger.Debugf("yay timemachine overflow time : %s --> %s", d, msg.MarshaledTime)
  22. l.Last_ts = d
  23. l.First_ts = d
  24. l.Ovflw_ts = d
  25. } else {
  26. l.Last_ts = time.Now().UTC()
  27. l.First_ts = time.Now().UTC()
  28. l.Ovflw_ts = time.Now().UTC()
  29. }
  30. l.Total_count = 1
  31. l.logger.Infof("Bucket overflow")
  32. l.Queue.Add(msg)
  33. l.Out <- l.Queue
  34. return nil
  35. }
  36. }