update retrieve channel logic

This commit is contained in:
liugq 2023-08-06 20:55:43 +08:00
parent bc27aafd7e
commit c9e68dd533
1 changed files with 18 additions and 3 deletions

View File

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