2020-05-15 09:39:16 +00:00
|
|
|
package leakybucket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
2021-10-12 12:09:17 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-05-15 09:39:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Trigger struct {
|
|
|
|
DumbProcessor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Trigger) OnBucketPour(b *BucketFactory) func(types.Event, *Leaky) *types.Event {
|
|
|
|
// Pour makes the bucket overflow all the time
|
2022-04-27 09:04:12 +00:00
|
|
|
// TriggerPour unconditionally overflows
|
2020-05-15 09:39:16 +00:00
|
|
|
return func(msg types.Event, l *Leaky) *types.Event {
|
2023-03-16 15:25:50 +00:00
|
|
|
if l.Mode == types.TIMEMACHINE {
|
2021-10-12 12:09:17 +00:00
|
|
|
var d time.Time
|
|
|
|
err := d.UnmarshalText([]byte(msg.MarshaledTime))
|
|
|
|
if err != nil {
|
|
|
|
log.Warningf("Failed unmarshaling event time (%s) : %v", msg.MarshaledTime, err)
|
2022-01-19 13:56:05 +00:00
|
|
|
d = time.Now().UTC()
|
2021-10-12 12:09:17 +00:00
|
|
|
}
|
|
|
|
l.logger.Debugf("yay timemachine overflow time : %s --> %s", d, msg.MarshaledTime)
|
|
|
|
l.Last_ts = d
|
|
|
|
l.First_ts = d
|
|
|
|
l.Ovflw_ts = d
|
|
|
|
} else {
|
2022-01-19 13:56:05 +00:00
|
|
|
l.Last_ts = time.Now().UTC()
|
|
|
|
l.First_ts = time.Now().UTC()
|
|
|
|
l.Ovflw_ts = time.Now().UTC()
|
2021-10-12 12:09:17 +00:00
|
|
|
}
|
2020-05-15 09:39:16 +00:00
|
|
|
l.Total_count = 1
|
2021-10-12 12:09:17 +00:00
|
|
|
|
2020-05-15 09:39:16 +00:00
|
|
|
l.logger.Infof("Bucket overflow")
|
|
|
|
l.Queue.Add(msg)
|
|
|
|
l.Out <- l.Queue
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|