(contextToSend map[string][]string, valueLength int)
| 44 | } |
| 45 | |
| 46 | func NewAlertContext(contextToSend map[string][]string, valueLength int) error { |
| 47 | if valueLength == 0 { |
| 48 | log.Debugf("No console context value length provided, using default: %d", MaxContextValueLen) |
| 49 | valueLength = MaxContextValueLen |
| 50 | } |
| 51 | |
| 52 | if valueLength > MaxContextValueLen { |
| 53 | log.Debugf("Provided console context value length (%d) is higher than the maximum, using default: %d", valueLength, MaxContextValueLen) |
| 54 | valueLength = MaxContextValueLen |
| 55 | } |
| 56 | |
| 57 | ac := Context{ |
| 58 | ContextToSend: contextToSend, |
| 59 | ContextValueLen: valueLength, |
| 60 | ContextToSendCompiled: make(map[string][]*vm.Program), |
| 61 | } |
| 62 | |
| 63 | for key, values := range contextToSend { |
| 64 | if _, ok := ac.ContextToSend[key]; !ok { |
| 65 | ac.ContextToSend[key] = make([]string, 0) |
| 66 | } |
| 67 | |
| 68 | if _, ok := ac.ContextToSendCompiled[key]; !ok { |
| 69 | ac.ContextToSendCompiled[key] = make([]*vm.Program, 0) |
| 70 | } |
| 71 | |
| 72 | for _, value := range values { |
| 73 | valueCompiled, err := expr.Compile(value, exprhelpers.GetExprOptions(map[string]any{ |
| 74 | "evt": &pipeline.Event{}, |
| 75 | "match": &pipeline.MatchedRule{}, |
| 76 | "req": &http.Request{}, |
| 77 | })...) |
| 78 | if err != nil { |
| 79 | return fmt.Errorf("compilation of '%s' context value failed: %w", value, err) |
| 80 | } |
| 81 | |
| 82 | ac.ContextToSendCompiled[key] = append(ac.ContextToSendCompiled[key], valueCompiled) |
| 83 | ac.ContextToSend[key] = append(ac.ContextToSend[key], value) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | alertContext.Store(&ac) |
| 88 | |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | func getAlertContext() *Context { |
| 93 | if ac := alertContext.Load(); ac != nil { |
searching dependent graphs…