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