enable_in_bg logic

This commit is contained in:
Ulric Qin 2022-01-08 17:52:29 +08:00
parent 7b4eddc967
commit d590f6d5c1
3 changed files with 14 additions and 6 deletions

View File

@ -207,6 +207,7 @@ CREATE TABLE `alert_rule` (
`enable_stime` char(5) not null default '00:00',
`enable_etime` char(5) not null default '23:59',
`enable_days_of_week` varchar(32) not null default '' comment 'split by space: 0 1 2 3 4 5 6',
`enable_in_bg` tinyint(1) not null default 0 comment '1: only this bg 0: global',
`notify_recovered` tinyint(1) not null comment 'whether notify when recovery',
`notify_channels` varchar(255) not null default '' comment 'split by space: sms voice email dingtalk wecom',
`notify_groups` varchar(255) not null default '' comment 'split by space: 233 43',

View File

@ -28,6 +28,7 @@ type AlertRule struct {
EnableEtime string `json:"enable_etime"` // e.g. 23:59
EnableDaysOfWeek string `json:"-"` // split by space: 0 1 2 3 4 5 6
EnableDaysOfWeekJSON []string `json:"enable_days_of_week" gorm:"-"` // for fe
EnableInBG int `json:"enable_in_bg"` // 0: global 1: enable one busi-group
NotifyRecovered int `json:"notify_recovered"` // whether notify when recovery
NotifyChannels string `json:"-"` // split by space: sms voice email dingtalk wecom
NotifyChannelsJSON []string `json:"notify_channels" gorm:"-"` // for fe

View File

@ -202,6 +202,12 @@ func (r RuleEval) judge(vectors []Vector) {
tagsMap[string(label)] = string(value)
}
// handle rule tags
for _, tag := range r.rule.AppendTagsJSON {
arr := strings.SplitN(tag, "=", 2)
tagsMap[arr[0]] = arr[1]
}
// handle target note
targetIdent, has := vectors[i].Labels["ident"]
targetNote := ""
@ -209,13 +215,13 @@ func (r RuleEval) judge(vectors []Vector) {
target, exists := memsto.TargetCache.Get(string(targetIdent))
if exists {
targetNote = target.Note
}
}
// handle rule tags
for _, tag := range r.rule.AppendTagsJSON {
arr := strings.SplitN(tag, "=", 2)
tagsMap[arr[0]] = arr[1]
// 对于包含ident的告警事件check一下ident所属bg和rule所属bg是否相同
// 如果告警规则选择了只在本BG生效那其他BG的机器就不能因此规则产生告警
if r.rule.EnableInBG == 1 && target.GroupId != r.rule.GroupId {
continue
}
}
}
event := &models.AlertCurEvent{