diff --git a/pkg/notify/models/notification.go b/pkg/notify/models/notification.go index e1e32e15dc..d3e6275fdc 100644 --- a/pkg/notify/models/notification.go +++ b/pkg/notify/models/notification.go @@ -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 { diff --git a/pkg/notify/sender/email.go b/pkg/notify/sender/email.go index a67e986d86..1e0e46e99e 100644 --- a/pkg/notify/sender/email.go +++ b/pkg/notify/sender/email.go @@ -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) diff --git a/pkg/notify/tasks/notifications_send_task.go b/pkg/notify/tasks/notifications_send_task.go index bcd493ac19..f65cf8e8d6 100644 --- a/pkg/notify/tasks/notifications_send_task.go +++ b/pkg/notify/tasks/notifications_send_task.go @@ -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