diff --git a/src/server/engine/mute.go b/src/server/engine/mute.go index 9fedd1a3..5d14d119 100644 --- a/src/server/engine/mute.go +++ b/src/server/engine/mute.go @@ -35,31 +35,36 @@ func matchMute(event *models.AlertCurEvent, mute *models.AlertMute, clock ...int return matchTags(tg, mute.ITags) } +func matchTag(value string, filter models.TagFilter) bool { + switch filter.Func { + case "==": + return filter.Value == value + case "!=": + return filter.Value != value + case "in": + _, has := filter.Vset[value] + return has + case "not in": + _, has := filter.Vset[value] + return !has + case "=~": + return filter.Regexp.MatchString(value) + case "!~": + return !filter.Regexp.MatchString(value) + } + // unexpect func + return false +} + func matchTags(eventTagsMap map[string]string, itags []models.TagFilter) bool { - for i := 0; i < len(itags); i++ { - filter := itags[i] - value, exists := eventTagsMap[filter.Key] - if !exists { + for _, filter := range itags { + value, has := eventTagsMap[filter.Key] + if !has { return false } - - if filter.Func == "==" { - // == - if filter.Value != value { - return false - } - } else if filter.Func == "in" { - // in - if _, has := filter.Vset[value]; !has { - return false - } - } else { - // =~ - if !filter.Regexp.MatchString(value) { - return false - } + if !matchTag(value, filter) { + return false } } - return true } diff --git a/src/webapi/router/router_mw.go b/src/webapi/router/router_mw.go index 01619db9..dd99b874 100644 --- a/src/webapi/router/router_mw.go +++ b/src/webapi/router/router_mw.go @@ -48,6 +48,9 @@ func handleProxyUser(c *gin.Context) *models.User { UpdateBy: "system", } err = user.Add() + if err != nil { + ginx.Bomb(http.StatusInternalServerError, err.Error()) + } } return user }