default to enabled channel of old rule data

This commit is contained in:
liugq 2023-07-28 18:16:46 +08:00
parent d42c05c8fb
commit fcf0179335
3 changed files with 16 additions and 4 deletions

View File

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

View File

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

View File

@ -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 {