Feature mute enhancement (#1041)

* [feature(#1029)] alert mute enhancement

* handle error of proxy user Add
This commit is contained in:
xiaoziv 2022-07-09 22:06:33 +08:00 committed by GitHub
parent 7359a69223
commit 5bc8f0b9b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 21 deletions

View File

@ -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
}

View File

@ -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
}