fix send message
This commit is contained in:
parent
8f1fd17f5c
commit
c71264ab30
|
@ -54,6 +54,7 @@ func DoNotify(isUpgrade bool, events ...*models.Event) {
|
||||||
|
|
||||||
notifyTypes := config.Config.Monapi.Notify[prio]
|
notifyTypes := config.Config.Monapi.Notify[prio]
|
||||||
for i := 0; i < len(notifyTypes); i++ {
|
for i := 0; i < len(notifyTypes); i++ {
|
||||||
|
var err error
|
||||||
switch notifyTypes[i] {
|
switch notifyTypes[i] {
|
||||||
case "voice":
|
case "voice":
|
||||||
if events[0].EventType == models.ALERT {
|
if events[0].EventType == models.ALERT {
|
||||||
|
@ -62,34 +63,36 @@ func DoNotify(isUpgrade bool, events ...*models.Event) {
|
||||||
tos = append(tos, users[j].Phone)
|
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":
|
case "sms":
|
||||||
tos := []string{}
|
tos := []string{}
|
||||||
for j := 0; j < len(users); j++ {
|
for j := 0; j < len(users); j++ {
|
||||||
tos = append(tos, users[j].Phone)
|
tos = append(tos, users[j].Phone)
|
||||||
}
|
}
|
||||||
|
|
||||||
send(slice.Set(tos), content, "", "sms")
|
err = send(slice.Set(tos), content, "", "sms")
|
||||||
case "mail":
|
case "mail":
|
||||||
tos := []string{}
|
tos := []string{}
|
||||||
for j := 0; j < len(users); j++ {
|
for j := 0; j < len(users); j++ {
|
||||||
tos = append(tos, users[j].Email)
|
tos = append(tos, users[j].Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := send(slice.Set(tos), mailContent, subject, "mail"); err == nil {
|
err = send(slice.Set(tos), mailContent, subject, "mail")
|
||||||
logger.Infof("sendMail: %+v", events[0])
|
|
||||||
}
|
|
||||||
case "im":
|
case "im":
|
||||||
tos := []string{}
|
tos := []string{}
|
||||||
for j := 0; j < len(users); j++ {
|
for j := 0; j < len(users); j++ {
|
||||||
tos = append(tos, users[j].Im)
|
tos = append(tos, users[j].Im)
|
||||||
}
|
}
|
||||||
|
|
||||||
send(slice.Set(tos), content, "", "im")
|
err = send(slice.Set(tos), content, "", "im")
|
||||||
default:
|
default:
|
||||||
logger.Errorf("not support %s to send notify, events: %+v", notifyTypes[i], events)
|
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")
|
return fmt.Errorf("tos is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message.Tos = tos
|
||||||
message.Content = strings.TrimSpace(content)
|
message.Content = strings.TrimSpace(content)
|
||||||
if message.Content == "" {
|
if message.Content == "" {
|
||||||
return fmt.Errorf("content is blank")
|
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)
|
redisc.Write(&message, cron.IM_QUEUE_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Infof("write %s message:%+v", message, notifyType)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue