From c71264ab304ce4cf8f9392a8f71385b6e35ddb2b Mon Sep 17 00:00:00 2001 From: 710leo <710leo@gmail.com> Date: Mon, 19 Apr 2021 20:10:29 +0800 Subject: [PATCH] fix send message --- src/modules/server/notify/notify.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modules/server/notify/notify.go b/src/modules/server/notify/notify.go index 1e591b37..af1ee6af 100644 --- a/src/modules/server/notify/notify.go +++ b/src/modules/server/notify/notify.go @@ -54,6 +54,7 @@ func DoNotify(isUpgrade bool, events ...*models.Event) { notifyTypes := config.Config.Monapi.Notify[prio] for i := 0; i < len(notifyTypes); i++ { + var err error switch notifyTypes[i] { case "voice": if events[0].EventType == models.ALERT { @@ -62,34 +63,36 @@ func DoNotify(isUpgrade bool, events ...*models.Event) { tos = append(tos, users[j].Phone) } - send(slice.Set(tos), events[0].Sname, "", "voice") + err = send(slice.Set(tos), events[0].Sname, "", "voice") } + case "sms": tos := []string{} for j := 0; j < len(users); j++ { tos = append(tos, users[j].Phone) } - send(slice.Set(tos), content, "", "sms") + err = send(slice.Set(tos), content, "", "sms") case "mail": tos := []string{} for j := 0; j < len(users); j++ { tos = append(tos, users[j].Email) } - if err := send(slice.Set(tos), mailContent, subject, "mail"); err == nil { - logger.Infof("sendMail: %+v", events[0]) - } + err = send(slice.Set(tos), mailContent, subject, "mail") case "im": tos := []string{} for j := 0; j < len(users); j++ { tos = append(tos, users[j].Im) } - send(slice.Set(tos), content, "", "im") + err = send(slice.Set(tos), content, "", "im") default: logger.Errorf("not support %s to send notify, events: %+v", notifyTypes[i], events) } + if err != nil { + logger.Errorf("send %s users:%+v content:%s err:%v", notifyTypes[i], users, content, err) + } } } @@ -411,6 +414,7 @@ func send(tos []string, content, subject, notifyType string) error { return fmt.Errorf("tos is empty") } + message.Tos = tos message.Content = strings.TrimSpace(content) if message.Content == "" { return fmt.Errorf("content is blank") @@ -434,6 +438,8 @@ func send(tos []string, content, subject, notifyType string) error { redisc.Write(&message, cron.IM_QUEUE_NAME) } + logger.Infof("write %s message:%+v", message, notifyType) + return nil }