From c9e68dd533c01f684f8e097f0f37e1166db7d60c Mon Sep 17 00:00:00 2001 From: liugq Date: Sun, 6 Aug 2023 20:55:43 +0800 Subject: [PATCH] update retrieve channel logic --- service/alerting/common/helper.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/service/alerting/common/helper.go b/service/alerting/common/helper.go index faf5e344..d89ba4a2 100644 --- a/service/alerting/common/helper.go +++ b/service/alerting/common/helper.go @@ -76,13 +76,28 @@ 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) + refCh := &alerting.Channel{} + _, err := orm.Get(refCh) if err != nil { return nil, err } - ch.Enabled = enabled + ch.Type = refCh.Type + ch.Name = refCh.Name + ch.SubType = refCh.SubType + switch ch.Type { + case alerting.ChannelEmail: + if ch.Email == nil { + ch.Email = refCh.Email + }else{ + ch.Email.ServerID = refCh.Email.ServerID + ch.Email.Recipients = refCh.Email.Recipients + } + case alerting.ChannelWebhook: + if ch.Webhook == nil { + ch.Webhook = refCh.Webhook + } + } } return ch, nil } \ No newline at end of file