Fix alerts regex filtering

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan 2021-02-23 12:55:57 +02:00
parent f8ae11cbca
commit c640ea8e36
No known key found for this signature in database
GPG Key ID: 3299AEB0E4085BAF
1 changed files with 6 additions and 1 deletions

View File

@ -75,17 +75,22 @@ func (s *EventServer) handleEvent() func(w http.ResponseWriter, r *http.Request)
}
// skip alert if the message matches a regex from the exclusion list
var skip bool
if len(alert.Spec.ExclusionList) > 0 {
for _, exp := range alert.Spec.ExclusionList {
if r, err := regexp.Compile(exp); err == nil {
if r.Match([]byte(event.Message)) {
continue
skip = true
break
}
} else {
s.logger.Error(err, fmt.Sprintf("failed to compile regex: %s", exp))
}
}
}
if skip {
continue
}
// filter alerts by object and severity
for _, source := range alert.Spec.EventSources {