add recover_time

This commit is contained in:
Ulric Qin 2021-12-08 00:07:25 +08:00
parent 2bfc67686d
commit 0e88f0074c
7 changed files with 19 additions and 7 deletions

View File

@ -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`),

View File

@ -2,5 +2,5 @@
规则名称: {{.RuleName}}{{if .RuleNote}}
规则备注: {{.RuleNote}}{{end}}
监控指标: {{.TagsJSON}}
触发时间: {{timeformat .TriggerTime}}
触发时值: {{.TriggerValue}}
{{if .IsRecovered}}恢复时间:{{timeformat .LastEvalTime}}{{else}}触发时间: {{timeformat .TriggerTime}}
触发时值: {{.TriggerValue}}{{end}}

View File

@ -2,5 +2,5 @@
规则名称: {{.RuleName}}{{if .RuleNote}}
规则备注: {{.RuleNote}}{{end}}
监控指标: {{.TagsJSON}}
触发时间: {{timeformat .TriggerTime}}
触发时值: {{.TriggerValue}}
{{if .IsRecovered}}恢复时间:{{timeformat .LastEvalTime}}{{else}}触发时间: {{timeformat .TriggerTime}}
触发时值: {{.TriggerValue}}{{end}}

View File

@ -162,6 +162,13 @@
<th>监控指标:</th>
<td>{{.TagsJSON}}</td>
</tr>
{{if .IsRecovered}}
<tr>
<th>恢复时间:</th>
<td>{{timeformat .LastEvalTime}}</td>
</tr>
{{else}}
<tr>
<th>触发时值:</th>
<td>{{.TriggerValue}}</td>
@ -172,6 +179,8 @@
{{timeformat .TriggerTime}}
</td>
</tr>
{{end}}
<tr>
<th>PromQL</th>
<td>

View File

@ -2,5 +2,5 @@
**规则标题**: {{.RuleName}}{{if .RuleNote}}
**规则备注**: {{.RuleNote}}{{end}}
**监控指标**: {{.TagsJSON}}
**触发时间**: {{timeformat .TriggerTime}}
**触发时值**: {{.TriggerValue}}
{{if .IsRecovered}}**恢复时间**{{timeformat .LastEvalTime}}{{else}}**触发时间**: {{timeformat .TriggerTime}}
**触发时值**: {{.TriggerValue}}{{end}}

View File

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

View File

@ -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:"-"`
}