From 0e88f0074c0a735483f44d8ef7e944356acc1b89 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Wed, 8 Dec 2021 00:07:25 +0800 Subject: [PATCH] add recover_time --- docker/initsql/n9e.sql | 1 + etc/template/dingtalk.tpl | 4 ++-- etc/template/feishu.tpl | 4 ++-- etc/template/mailbody.tpl | 9 +++++++++ etc/template/wecom.tpl | 4 ++-- src/models/alert_cur_event.go | 3 ++- src/models/alert_his_event.go | 1 + 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docker/initsql/n9e.sql b/docker/initsql/n9e.sql index e2cf8806..44285c57 100644 --- a/docker/initsql/n9e.sql +++ b/docker/initsql/n9e.sql @@ -318,6 +318,7 @@ CREATE TABLE `alert_his_event` ( `target_note` varchar(191) not null default '' comment 'target note', `trigger_time` bigint not null, `trigger_value` varchar(255) not null, + `recover_time` bigint not null default 0, `tags` varchar(1024) not null default '' comment 'merge data_tags rule_tags, split by ,,', PRIMARY KEY (`id`), KEY (`hash`), diff --git a/etc/template/dingtalk.tpl b/etc/template/dingtalk.tpl index 95019eba..59ece247 100644 --- a/etc/template/dingtalk.tpl +++ b/etc/template/dingtalk.tpl @@ -2,5 +2,5 @@ 规则名称: {{.RuleName}}{{if .RuleNote}} 规则备注: {{.RuleNote}}{{end}} 监控指标: {{.TagsJSON}} -触发时间: {{timeformat .TriggerTime}} -触发时值: {{.TriggerValue}} \ No newline at end of file +{{if .IsRecovered}}恢复时间:{{timeformat .LastEvalTime}}{{else}}触发时间: {{timeformat .TriggerTime}} +触发时值: {{.TriggerValue}}{{end}} \ No newline at end of file diff --git a/etc/template/feishu.tpl b/etc/template/feishu.tpl index 95019eba..59ece247 100644 --- a/etc/template/feishu.tpl +++ b/etc/template/feishu.tpl @@ -2,5 +2,5 @@ 规则名称: {{.RuleName}}{{if .RuleNote}} 规则备注: {{.RuleNote}}{{end}} 监控指标: {{.TagsJSON}} -触发时间: {{timeformat .TriggerTime}} -触发时值: {{.TriggerValue}} \ No newline at end of file +{{if .IsRecovered}}恢复时间:{{timeformat .LastEvalTime}}{{else}}触发时间: {{timeformat .TriggerTime}} +触发时值: {{.TriggerValue}}{{end}} \ No newline at end of file diff --git a/etc/template/mailbody.tpl b/etc/template/mailbody.tpl index a45e35b6..fa5e2d64 100644 --- a/etc/template/mailbody.tpl +++ b/etc/template/mailbody.tpl @@ -162,6 +162,13 @@ 监控指标: {{.TagsJSON}} + + {{if .IsRecovered}} + + 恢复时间: + {{timeformat .LastEvalTime}} + + {{else}} 触发时值: {{.TriggerValue}} @@ -172,6 +179,8 @@ {{timeformat .TriggerTime}} + {{end}} + PromQL: diff --git a/etc/template/wecom.tpl b/etc/template/wecom.tpl index 1513cbd5..d1c7410a 100644 --- a/etc/template/wecom.tpl +++ b/etc/template/wecom.tpl @@ -2,5 +2,5 @@ **规则标题**: {{.RuleName}}{{if .RuleNote}} **规则备注**: {{.RuleNote}}{{end}} **监控指标**: {{.TagsJSON}} -**触发时间**: {{timeformat .TriggerTime}} -**触发时值**: {{.TriggerValue}} \ No newline at end of file +{{if .IsRecovered}}**恢复时间**:{{timeformat .LastEvalTime}}{{else}}**触发时间**: {{timeformat .TriggerTime}} +**触发时值**: {{.TriggerValue}}{{end}} \ No newline at end of file diff --git a/src/models/alert_cur_event.go b/src/models/alert_cur_event.go index a43b64d1..a278bd90 100644 --- a/src/models/alert_cur_event.go +++ b/src/models/alert_cur_event.go @@ -37,7 +37,7 @@ type AlertCurEvent struct { TagsMap map[string]string `json:"-" gorm:"-"` // for internal usage IsRecovered bool `json:"is_recovered" gorm:"-"` // for notify.py NotifyUsersObj []*User `json:"notify_users_obj" gorm:"-"` // for notify.py - LastEvalTime int64 `json:"last_eval_time" gorm:"-"` // for internal usage + LastEvalTime int64 `json:"last_eval_time" gorm:"-"` // for notify.py } func (e *AlertCurEvent) TableName() string { @@ -80,6 +80,7 @@ func (e *AlertCurEvent) ToHis() *AlertHisEvent { TriggerTime: e.TriggerTime, TriggerValue: e.TriggerValue, Tags: e.Tags, + RecoverTime: e.LastEvalTime, } } diff --git a/src/models/alert_his_event.go b/src/models/alert_his_event.go index 39eb89a2..507c1a5c 100644 --- a/src/models/alert_his_event.go +++ b/src/models/alert_his_event.go @@ -31,6 +31,7 @@ type AlertHisEvent struct { TargetNote string `json:"target_note"` TriggerTime int64 `json:"trigger_time"` TriggerValue string `json:"trigger_value"` + RecoverTime int64 `json:"recover_time"` Tags string `json:"-"` TagsJSON []string `json:"tags" gorm:"-"` } -- GitLab