-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor.go
51 lines (42 loc) · 1.23 KB
/
executor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import "log"
type Executor interface {
Enrich(alerts []Alert) ([]Alert, error)
}
type SimpleExecutor struct {
ruleMatcher RuleMatcher
workflowEngine WorkflowEngine
logger *log.Logger
}
// verify interface compliance
var _ Executor = (*SimpleExecutor)(nil)
func NewSimpleExecutor(ruleMatcher RuleMatcher, workflowEngine WorkflowEngine, logger *log.Logger) *SimpleExecutor {
return &SimpleExecutor{
ruleMatcher: ruleMatcher,
workflowEngine: workflowEngine,
logger: logger,
}
}
func (se *SimpleExecutor) Enrich(alerts []Alert) ([]Alert, error) {
var wfPayloads []PayloadWorkflows
for _, alert := range alerts {
workflows := se.ruleMatcher.Match(alert)
wfPayloads = append(wfPayloads, PayloadWorkflows{
WorkflowIDs: workflows,
Payload: WorkflowPayload(alert),
})
}
se.logger.Printf("mapped payloads: %v", wfPayloads)
results, err := se.workflowEngine.Run(wfPayloads)
if err != nil {
se.logger.Printf("failed to run workflows: %v", err)
return nil, err
}
se.logger.Printf("results: %v", results)
// Convert results to Alerts
var enrichedAlerts []Alert
for _, result := range results {
enrichedAlerts = append(enrichedAlerts, Alert(result))
}
return enrichedAlerts, nil
}