mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
feat(monitor): alert record add silentPeriod info
1.报警记录中增加静默期等信息
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user