feat(monitor): alert record add silentPeriod info

1.报警记录中增加静默期等信息
This commit is contained in:
zhaoxiangchun
2021-02-05 19:56:38 +08:00
parent 4e0ce5b9e8
commit 730c13b837
4 changed files with 12 additions and 1 deletions
+2
View File
@@ -57,4 +57,6 @@ type AlertRecordRule struct {
Period string `json:"period"`
AlertDuration int64 `json:"alert_duration"`
ConditionType string `json:"condition_type"`
// 静默期
SilentPeriod string `json:"silent_period"`
}
+3
View File
@@ -251,5 +251,8 @@ func newAlertRecordRule(evalCtx *EvalContext) monitor.AlertRecordRule {
alertRule.AlertDuration = int64(evalCtx.Rule.For)/evalCtx.Rule.Frequency + 1
if evalCtx.Rule.SilentPeriod != 0 {
alertRule.SilentPeriod = fmt.Sprintf("%dm", evalCtx.Rule.SilentPeriod/60)
}
return alertRule
}
+6
View File
@@ -64,6 +64,8 @@ type Rule struct {
StateChanges int
CustomizeConfig jsonutils.JSONObject
// 静默期
SilentPeriod int64
}
var (
@@ -140,6 +142,10 @@ func NewRuleFromDBAlert(ruleDef *models.SAlert) (*Rule, error) {
return nil, err
}
for _, n := range notis {
noti, _ := n.GetNotification()
if noti.Frequency != 0 {
model.SilentPeriod = noti.Frequency
}
nIds = append(nIds, n.NotificationId)
}
model.Notifications = nIds
+1 -1
View File
@@ -229,7 +229,7 @@ func (n *SNotification) ShouldSendNotification() bool {
if n.Frequency == 0 {
return true
}
if int64(time.Now().Sub(n.LastSendNotification)/time.Second)+int64(time.Second*60) >= n.Frequency {
if int64(time.Now().Sub(n.LastSendNotification)/time.Second)+int64(60) >= n.Frequency {
return true
}
return false