Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/rules/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Engine struct {
psnap ps.Snapshotter

matches []*ruleMatch
mmu sync.Mutex // guards the rule matches slice
sequences []*sequenceState

scavenger *time.Ticker
Expand Down Expand Up @@ -306,6 +307,8 @@ func (e *Engine) ProcessEvent(evt *kevent.Kevent) (bool, error) {
// defined in the rule definition.
func (e *Engine) processActions() error {
defer e.clearMatches()
e.mmu.Lock()
defer e.mmu.Unlock()
for _, m := range e.matches {
f, evts := m.ctx.Filter, m.ctx.Events
filterMatches.Add(f.Name, 1)
Expand Down Expand Up @@ -344,12 +347,16 @@ func (e *Engine) appendMatch(f *config.FilterConfig, evts ...*kevent.Kevent) {
Events: evts,
Filter: f,
}
e.mmu.Lock()
defer e.mmu.Unlock()
e.matches = append(e.matches, &ruleMatch{ctx: ctx})
if e.matchFunc != nil {
e.matchFunc(f, evts...)
}
}

func (e *Engine) clearMatches() {
e.mmu.Lock()
defer e.mmu.Unlock()
e.matches = make([]*ruleMatch, 0)
}