diff --git a/plugin/api/alerting/rule.go b/plugin/api/alerting/rule.go index b0a260c5..db302f1d 100644 --- a/plugin/api/alerting/rule.go +++ b/plugin/api/alerting/rule.go @@ -138,6 +138,12 @@ func (alertAPI *AlertAPI) getRule(w http.ResponseWriter, req *http.Request, ps h // adapter version smaller than 1.6.0 if obj.Channels != nil && obj.NotificationConfig == nil { obj.NotificationConfig = obj.Channels + for i := range obj.NotificationConfig.Normal { + obj.NotificationConfig.Normal[i].Enabled = true + } + for i := range obj.NotificationConfig.Escalation { + obj.NotificationConfig.Escalation[i].Enabled = true + } } if obj.NotificationConfig != nil && obj.NotificationConfig.Message == "" && obj.Metrics.Message != "" { obj.NotificationConfig.Message = obj.Metrics.Message diff --git a/service/alerting/common/helper.go b/service/alerting/common/helper.go index fd8150b5..faf5e344 100644 --- a/service/alerting/common/helper.go +++ b/service/alerting/common/helper.go @@ -15,15 +15,14 @@ import ( ) func PerformChannel(channel *alerting.Channel, ctx map[string]interface{}) ([]byte, error, []byte) { + if channel == nil { + return nil, fmt.Errorf("empty channel"), nil + } var ( act action.Action message []byte err error ) - channel, err = RetrieveChannel(channel) - if err != nil { - return nil, err, nil - } switch channel.Type { case alerting.ChannelWebhook: @@ -77,11 +76,13 @@ func RetrieveChannel(ch *alerting.Channel) (*alerting.Channel, error) { if ch == nil { return nil, fmt.Errorf("empty channel") } + enabled := ch.Enabled if ch.ID != "" { _, err := orm.Get(ch) if err != nil { return nil, err } + ch.Enabled = enabled } return ch, nil } \ No newline at end of file diff --git a/service/alerting/elasticsearch/engine.go b/service/alerting/elasticsearch/engine.go index 9c314e9a..74ee4bc7 100644 --- a/service/alerting/elasticsearch/engine.go +++ b/service/alerting/elasticsearch/engine.go @@ -963,6 +963,11 @@ func performChannels(channels []alerting.Channel, ctx map[string]interface{}) ([ if !channel.Enabled { continue } + _, err := common.RetrieveChannel(&channel) + if err != nil { + log.Error(err) + continue + } resBytes, err, messageBytes := common.PerformChannel(&channel, ctx) var errStr string if err != nil {