diff --git a/pkg/cloudcommon/notifyclient/notify.go b/pkg/cloudcommon/notifyclient/notify.go index 60a720a2eb..b2aa98adb8 100644 --- a/pkg/cloudcommon/notifyclient/notify.go +++ b/pkg/cloudcommon/notifyclient/notify.go @@ -65,7 +65,9 @@ func init() { Obj: obj, Action: api.SAction(action), ObjDetailsDecorator: func(ctx context.Context, details *jsonutils.JSONDict) { - details.Set("customize_details", details) + if moreDetails != nil { + details.Set("customize_details", moreDetails) + } }, }) }) diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 4258d50c1e..7cf73f8a07 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -90,7 +90,7 @@ func init() { } HostManager.SetVirtualObject(HostManager) HostManager.SetAlias("baremetal", "baremetals") - notifyclient.AddNotifyDBHookResources(HostManager.KeywordPlural(), GuestManager.AliasPlural()) + notifyclient.AddNotifyDBHookResources(HostManager.KeywordPlural(), HostManager.AliasPlural()) GuestManager.NameRequireAscii = false } diff --git a/pkg/compute/tasks/instance_backup_create_task.go b/pkg/compute/tasks/instance_backup_create_task.go index dd28b3dea3..4d285d1ec1 100644 --- a/pkg/compute/tasks/instance_backup_create_task.go +++ b/pkg/compute/tasks/instance_backup_create_task.go @@ -50,11 +50,11 @@ func (self *InstanceBackupCreateTask) taskFailed(ctx context.Context, ib *models func (self *InstanceBackupCreateTask) taskSuccess(ctx context.Context, ib *models.SInstanceBackup, guest *models.SGuest) { ib.SetStatus(self.UserCred, compute.INSTANCE_BACKUP_STATUS_READY, "") logclient.AddActionLogWithStartable(self, ib, logclient.ACT_CREATE, nil, self.UserCred, true) - self.SetStageComplete(ctx, nil) notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{ Obj: guest, Action: notifyclient.ActionCreateBackupServer, }) + self.SetStageComplete(ctx, nil) } func (self *InstanceBackupCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { diff --git a/pkg/notify/models/event_template.go b/pkg/notify/models/event_template.go index 2dfef851fa..82c52fed32 100644 --- a/pkg/notify/models/event_template.go +++ b/pkg/notify/models/event_template.go @@ -394,5 +394,20 @@ func init() { "successfully", "成功", }, + sI18nElme{ + string(api.ActionAttach), + "attach", + "挂载", + }, + sI18nElme{ + string(api.ActionDetach), + "detach", + "卸载", + }, + sI18nElme{ + string(api.ActionCreateBackupServer), + "add_backup_server", + "添加主机备份", + }, ) } diff --git a/pkg/notify/models/notification.go b/pkg/notify/models/notification.go index 32af242b5b..323dfb65cf 100644 --- a/pkg/notify/models/notification.go +++ b/pkg/notify/models/notification.go @@ -273,10 +273,13 @@ func (nm *SNotificationManager) PerformEventNotify(ctx context.Context, userCred } receiverIdList := []string{} - for k, _ := range receiverIds { + for k := range receiverIds { receiverIdList = append(receiverIdList, k) } receivers, err := ReceiverManager.FetchByIdOrNames(ctx, receiverIdList...) + if err != nil { + return output, errors.Wrap(err, "fetch receiver") + } webconsoleContacts := sets.NewString() idSet := sets.NewString() for i := range receivers { @@ -626,7 +629,7 @@ func (n *SNotification) ReceiverNotificationsNotOK() ([]SReceiverNotification, e func (n *SNotification) receiveDetails(userCred mcclient.TokenCredential, scope string) ([]api.ReceiveDetail, error) { RQ := ReceiverManager.Query("id", "name") - q := ReceiverNotificationManager.Query("receiver_id", "notification_id", "receiver_type", "contact", "send_at", "send_by", "status", "failed_reason").Equals("notification_id", n.Id) + q := ReceiverNotificationManager.Query("receiver_id", "notification_id", "receiver_type", "contact", "send_at", "send_by", "status", "failed_reason").Equals("notification_id", n.Id).IsNotEmpty("receiver_id").IsNullOrEmpty("contact") s := rbacscope.TRbacScope(scope) switch s { diff --git a/pkg/notify/models/topic.go b/pkg/notify/models/topic.go index ef06862499..d1909f9724 100644 --- a/pkg/notify/models/topic.go +++ b/pkg/notify/models/topic.go @@ -292,6 +292,7 @@ func (sm *STopicManager) InitializeData() error { t.addAction( notify.ActionCreateBackupServer, ) + t.Results = tristate.True t.Type = notify.TOPIC_TYPE_RESOURCE case DefaultResourceSync: t.addResources( @@ -823,36 +824,41 @@ func init() { ) converter.registerAction( map[notify.SAction]int{ - notify.ActionCreate: 0, - notify.ActionDelete: 1, - notify.ActionPendingDelete: 2, - notify.ActionUpdate: 3, - notify.ActionRebuildRoot: 4, - notify.ActionResetPassword: 5, - notify.ActionChangeConfig: 6, - notify.ActionExpiredRelease: 7, - notify.ActionExecute: 8, - notify.ActionChangeIpaddr: 9, - notify.ActionSyncStatus: 10, - notify.ActionCleanData: 11, - notify.ActionMigrate: 12, - notify.ActionCreateBackupServer: 13, - notify.ActionDelBackupServer: 14, - notify.ActionSyncCreate: 15, - notify.ActionSyncUpdate: 16, - notify.ActionSyncDelete: 17, - notify.ActionOffline: 18, - notify.ActionSystemPanic: 19, - notify.ActionSystemException: 20, - notify.ActionChecksumTest: 21, - notify.ActionLock: 22, - notify.ActionExceedCount: 23, - notify.ActionSyncAccountStatus: 24, - notify.ActionPasswordExpireSoon: 25, - notify.ActionNetOutOfSync: 26, - notify.ActionMysqlOutOfSync: 27, - notify.ActionServiceAbnormal: 28, - notify.ActionServerPanicked: 29, + notify.ActionCreate: 0, + notify.ActionDelete: 1, + notify.ActionPendingDelete: 2, + notify.ActionUpdate: 3, + notify.ActionRebuildRoot: 4, + notify.ActionResetPassword: 5, + notify.ActionChangeConfig: 6, + notify.ActionExpiredRelease: 7, + notify.ActionExecute: 8, + notify.ActionChangeIpaddr: 9, + notify.ActionSyncStatus: 10, + notify.ActionCleanData: 11, + notify.ActionMigrate: 12, + notify.ActionCreateBackupServer: 13, + notify.ActionDelBackupServer: 14, + notify.ActionSyncCreate: 15, + notify.ActionSyncUpdate: 16, + notify.ActionSyncDelete: 17, + notify.ActionOffline: 18, + notify.ActionSystemPanic: 19, + notify.ActionSystemException: 20, + notify.ActionChecksumTest: 21, + notify.ActionLock: 22, + notify.ActionExceedCount: 23, + notify.ActionSyncAccountStatus: 24, + notify.ActionPasswordExpireSoon: 25, + notify.ActionNetOutOfSync: 26, + notify.ActionMysqlOutOfSync: 27, + notify.ActionServiceAbnormal: 28, + notify.ActionServerPanicked: 29, + notify.ActionAttach: 30, + notify.ActionDetach: 31, + notify.ActionIsolatedDeviceCreate: 32, + notify.ActionIsolatedDeviceUpdate: 33, + notify.ActionIsolatedDeviceDelete: 34, }, ) }