fix silence period not work when there is a channel throw error
This commit is contained in:
parent
9ad513d307
commit
dcb5a6cad0
|
@ -83,6 +83,10 @@ func RetrieveChannel(ch *alerting.Channel) (*alerting.Channel, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !refCh.Enabled {
|
||||||
|
ch.Enabled = false
|
||||||
|
return ch, nil
|
||||||
|
}
|
||||||
ch.Type = refCh.Type
|
ch.Type = refCh.Type
|
||||||
ch.Name = refCh.Name
|
ch.Name = refCh.Name
|
||||||
ch.SubType = refCh.SubType
|
ch.SubType = refCh.SubType
|
||||||
|
|
|
@ -801,16 +801,14 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if alertMessage == nil || period > periodDuration {
|
if alertMessage == nil || period > periodDuration {
|
||||||
actionResults, errCount := performChannels(notifyCfg.Normal, paramsCtx)
|
actionResults, _ := performChannels(notifyCfg.Normal, paramsCtx)
|
||||||
alertItem.ActionExecutionResults = actionResults
|
alertItem.ActionExecutionResults = actionResults
|
||||||
//change and save last notification time in local kv store when action error count equals zero
|
//change and save last notification time in local kv store when action error count equals zero
|
||||||
if errCount == 0 {
|
|
||||||
rule.LastNotificationTime = time.Now()
|
rule.LastNotificationTime = time.Now()
|
||||||
strTime := time.Now().UTC().Format(time.RFC3339)
|
strTime := time.Now().UTC().Format(time.RFC3339)
|
||||||
kv.AddValue(alerting2.KVLastNotificationTime, []byte(rule.ID), []byte(strTime))
|
kv.AddValue(alerting2.KVLastNotificationTime, []byte(rule.ID), []byte(strTime))
|
||||||
alertItem.IsNotified = true
|
alertItem.IsNotified = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if notifyCfg.EscalationEnabled {
|
if notifyCfg.EscalationEnabled {
|
||||||
throttlePeriod, err := time.ParseDuration(notifyCfg.EscalationThrottlePeriod)
|
throttlePeriod, err := time.ParseDuration(notifyCfg.EscalationThrottlePeriod)
|
||||||
|
@ -917,6 +915,7 @@ func newParameterCtx(rule *alerting.Rule, checkResults *alerting.ConditionResult
|
||||||
alerting2.ParamResourceID: rule.Resource.ID,
|
alerting2.ParamResourceID: rule.Resource.ID,
|
||||||
alerting2.ParamResourceName: rule.Resource.Name,
|
alerting2.ParamResourceName: rule.Resource.Name,
|
||||||
alerting2.ParamResults: conditionParams,
|
alerting2.ParamResults: conditionParams,
|
||||||
|
"objects": rule.Resource.Objects,
|
||||||
"first_group_value": firstGroupValue,
|
"first_group_value": firstGroupValue,
|
||||||
"first_threshold": firstThreshold,
|
"first_threshold": firstThreshold,
|
||||||
"rule_name": rule.Name,
|
"rule_name": rule.Name,
|
||||||
|
@ -990,14 +989,14 @@ func performChannels(channels []alerting.Channel, ctx map[string]interface{}) ([
|
||||||
var errCount int
|
var errCount int
|
||||||
var actionResults []alerting.ActionExecutionResult
|
var actionResults []alerting.ActionExecutionResult
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
if !channel.Enabled {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := common.RetrieveChannel(&channel)
|
_, err := common.RetrieveChannel(&channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if !channel.Enabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
resBytes, err, messageBytes := common.PerformChannel(&channel, ctx)
|
resBytes, err, messageBytes := common.PerformChannel(&channel, ctx)
|
||||||
var errStr string
|
var errStr string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue