processActions executes rule actions on behalf of rule matches. Actions are categorized into implicit and explicit actions. Sending an alert is an implicit action carried out each time there is a rule match. Other actions are executed if declared in the rule definition.
()
| 271 | // match. Other actions are executed if |
| 272 | // declared in the rule definition. |
| 273 | func (e *Engine) processActions() error { |
| 274 | defer e.clearMatches() |
| 275 | e.mmu.Lock() |
| 276 | defer e.mmu.Unlock() |
| 277 | for _, m := range e.matches { |
| 278 | f, evts := m.ctx.Filter, m.ctx.Events |
| 279 | filterMatches.Add(f.Name, 1) |
| 280 | log.Debugf("[%s] rule matched", f.Name) |
| 281 | err := action.Alert(m.ctx, f.Name, filter.InterpolateFields(f.Output, evts), f.Severity, f.Tags) |
| 282 | if err != nil { |
| 283 | return ErrRuleAction(f.Name, err) |
| 284 | } |
| 285 | |
| 286 | actions, err := f.DecodeActions() |
| 287 | if err != nil { |
| 288 | return err |
| 289 | } |
| 290 | |
| 291 | for _, act := range actions { |
| 292 | switch t := act.(type) { |
| 293 | case config.KillAction: |
| 294 | log.Infof("executing kill action: pids=%v rule=%s", m.ctx.UniquePids(), f.Name) |
| 295 | if err := action.Kill(m.ctx.UniquePids()); err != nil { |
| 296 | return ErrRuleAction(f.Name, err) |
| 297 | } |
| 298 | case config.IsolateAction: |
| 299 | log.Infof("executing isolate action: rule=%s", f.Name) |
| 300 | if err := action.Isolate(t.Whitelist); err != nil { |
| 301 | return ErrRuleAction(f.Name, err) |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | return nil |
| 308 | } |
| 309 | |
| 310 | func (e *Engine) appendMatch(f *config.FilterConfig, evts ...*event.Event) { |
| 311 | for _, evt := range evts { |
no test coverage detected