fix(notify): notify receiver (#24300)

This commit is contained in:
屈轩
2026-02-09 20:42:52 +08:00
committed by GitHub
parent 0b02c49c7c
commit 7dc2246c10
3 changed files with 13 additions and 13 deletions
+9 -11
View File
@@ -262,13 +262,10 @@ func (nm *SNotificationManager) PerformEventNotify(ctx context.Context, userCred
message := jsonutils.Marshal(input.ResourceDetails).String()
// append default receiver
if len(input.Event) == 0 {
for _, receiver := range input.ReceiverIds {
// receiverIds = append(receiverIds, api.SReceiverWithGroupTimes{ReceiverId: receiver})
if _, ok := receiverIds[receiver]; !ok {
receiverIds[receiver] = 0
}
for _, receiver := range input.ReceiverIds {
// receiverIds = append(receiverIds, api.SReceiverWithGroupTimes{ReceiverId: receiver})
if _, ok := receiverIds[receiver]; !ok {
receiverIds[receiver] = 0
}
}
@@ -316,6 +313,7 @@ func (nm *SNotificationManager) PerformEventNotify(ctx context.Context, userCred
}
err := nm.create(ctx, userCred, ct, realReceiverIds, nil, input.Priority, event.GetId(), topic.GetId(), topic.Type)
if err != nil {
log.Errorf("unable to create notification for %s: %v", ct, err)
output.FailedList = append(output.FailedList, api.FailedElem{
ContactType: ct,
Reason: err.Error(),
@@ -324,6 +322,7 @@ func (nm *SNotificationManager) PerformEventNotify(ctx context.Context, userCred
}
err = nm.createWithWebhookRobots(ctx, userCred, webhookRobots, input.Priority, event.GetId(), topic.Type)
if err != nil {
log.Errorf("unable to create notification for webhook robots: %v", err)
output.FailedList = append(output.FailedList, api.FailedElem{
ContactType: api.WEBHOOK,
Reason: err.Error(),
@@ -332,6 +331,7 @@ func (nm *SNotificationManager) PerformEventNotify(ctx context.Context, userCred
// robot
err = nm.createWithRobots(ctx, userCred, realRobot, input.Priority, event.GetId(), topic.Type)
if err != nil {
log.Errorf("unable to create notification for robots: %v", err)
output.FailedList = append(output.FailedList, api.FailedElem{
ContactType: api.ROBOT,
Reason: err.Error(),
@@ -488,11 +488,9 @@ func (nm *SNotificationManager) create(ctx context.Context, userCred mcclient.To
n.SetModelManager(nm, n)
task, err := taskman.TaskManager.NewTask(ctx, "NotificationSendTask", n, userCred, nil, "", "")
if err != nil {
log.Errorf("NotificationSendTask newTask error %v", err)
} else {
task.ScheduleRun(nil)
return errors.Wrapf(err, "NewTask")
}
return nil
return task.ScheduleRun(nil)
}
func (nm *SNotificationManager) createWithWebhookRobots(ctx context.Context, userCred mcclient.TokenCredential, webhookRobotIds []string, priority, eventId string, topicType string) error {
+1
View File
@@ -129,6 +129,7 @@ func (emailSender *SEmailSender) Send(ctx context.Context, args api.SendParams)
errs := make([]error, 0)
for tryTime := 3; tryTime > 0; tryTime-- {
err = gomail.Send(sender, gmsg)
log.Debugf("send %s to %s email err: %v", args.EmailMsg.Subject, to, err)
if err != nil {
errs = append(errs, errors.Wrapf(err, "Send"))
time.Sleep(time.Second * 10)
+3 -2
View File
@@ -140,7 +140,8 @@ func (self *NotificationSendTask) OnInit(ctx context.Context, obj db.IStandalone
continue
}
if !verified {
sendFail(&rns[i], fmt.Sprintf("unverified contactType %q", notification.ContactType))
contact, _ := receiver.GetContact(notification.ContactType)
sendFail(&rns[i], fmt.Sprintf("unverified contactType %q for contact %s", notification.ContactType, contact))
continue
}
lang, err := receiver.GetTemplateLang(ctx)
@@ -179,7 +180,7 @@ func (self *NotificationSendTask) OnInit(ctx context.Context, obj db.IStandalone
apis.TEMPLATE_LANG_EN: receiversEn,
} {
if len(receivers) == 0 {
log.Warningf("no receiver to send, skip ...")
log.Warningf("no receiver to send for %s %s, skip ...", notification.ContactType, lang)
continue
}
// send