提交 d590f6d5 编写于 作者: U Ulric Qin

enable_in_bg logic

上级 7b4eddc9
......@@ -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',
......
......@@ -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
......
......@@ -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{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册