diff --git a/cmd/climc/shell/events/events.go b/cmd/climc/shell/events/events.go index 43642b612c..cbbf79cb9f 100644 --- a/cmd/climc/shell/events/events.go +++ b/cmd/climc/shell/events/events.go @@ -74,6 +74,10 @@ func doMonitorEventList(s *mcclient.ClientSession, args *EventListOptions) error return DoEventList(modules.MonitorLogs, s, args) } +func doNotifyEventList(s *mcclient.ClientSession, args *EventListOptions) error { + return DoEventList(modules.NotifyLogs, s, args) +} + func DoEventList(man modulebase.ResourceManager, s *mcclient.ClientSession, args *EventListOptions) error { params := jsonutils.NewDict() if len(args.Type) > 0 { @@ -262,4 +266,9 @@ func init() { nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"migrationalert"}} return doMonitorEventList(s, &nargs) }) + + R(&TypeEventListOptions{}, "notification-event", "Show operation event logs of a notification", func(s *mcclient.ClientSession, args *TypeEventListOptions) error { + nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"notification"}} + return doNotifyEventList(s, &nargs) + }) } diff --git a/pkg/apis/notify/notification.go b/pkg/apis/notify/notification.go index 097b8f4dd7..b2543deeea 100644 --- a/pkg/apis/notify/notification.go +++ b/pkg/apis/notify/notification.go @@ -63,6 +63,7 @@ type ReceiveDetail struct { ReceiverId string `json:"receiver_id"` ReceiverName string `json:"receiver_name"` Contact string `json:"contact"` + ReceiverType string `json:"receiver_type"` SendAt time.Time `json:"sendAt"` SendBy string `json:"send_by"` Status string `json:"status"` diff --git a/pkg/compute/models/dbinstances.go b/pkg/compute/models/dbinstances.go index 13489deb0c..3016a6ac6b 100644 --- a/pkg/compute/models/dbinstances.go +++ b/pkg/compute/models/dbinstances.go @@ -2111,3 +2111,11 @@ func (manager *SDBInstanceManager) GetExpiredModels(advanceDay int) ([]IBillingM func (self *SDBInstance) GetExpiredAt() time.Time { return self.ExpiredAt } + +func (db *SDBInstance) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { + db.SVirtualResourceBase.PostUpdate(ctx, userCred, query, data) + notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{ + Obj: db, + Action: notifyclient.ActionUpdate, + }) +} diff --git a/pkg/compute/models/elastic_search.go b/pkg/compute/models/elastic_search.go index dbb44407a8..a7a7e0c91e 100644 --- a/pkg/compute/models/elastic_search.go +++ b/pkg/compute/models/elastic_search.go @@ -652,3 +652,11 @@ func (self *SElasticSearch) GetDetailsAccessInfo(ctx context.Context, userCred m } return iEs.GetAccessInfo() } + +func (es *SElasticSearch) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { + es.SVirtualResourceBase.PostUpdate(ctx, userCred, query, data) + notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{ + Obj: es, + Action: notifyclient.ActionUpdate, + }) +} diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 695dd0a3ed..a187d2a508 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1884,6 +1884,10 @@ func (self *SGuest) PostUpdate(ctx context.Context, userCred mcclient.TokenCrede log.Errorf("unable to set sshport for guest %s", self.GetId()) } } + notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{ + Obj: self, + Action: notifyclient.ActionUpdate, + }) } func (manager *SGuestManager) checkCreateQuota( diff --git a/pkg/keystone/models/users.go b/pkg/keystone/models/users.go index 58cb606e06..6ddecb499b 100644 --- a/pkg/keystone/models/users.go +++ b/pkg/keystone/models/users.go @@ -29,6 +29,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/consts" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas" + "yunion.io/x/onecloud/pkg/cloudcommon/notifyclient" "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/keystone/options" @@ -778,6 +779,10 @@ func (user *SUser) PostUpdate(ctx context.Context, userCred mcclient.TokenCreden log.Errorf("unable to clear failed auth: %v", err) } } + notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{ + Obj: user, + Action: notifyclient.ActionUpdate, + }) } func (user *SUser) ValidateDeleteCondition(ctx context.Context, info jsonutils.JSONObject) error { diff --git a/pkg/mcclient/modules/mod_logs.go b/pkg/mcclient/modules/mod_logs.go index 10ad1ccab5..aa482e28a5 100644 --- a/pkg/mcclient/modules/mod_logs.go +++ b/pkg/mcclient/modules/mod_logs.go @@ -34,6 +34,7 @@ var ( CloudeventLogs modulebase.ResourceManager ComputeLogs modulebase.ResourceManager MonitorLogs modulebase.ResourceManager + NotifyLogs modulebase.ResourceManager ) func (this *LogsManager) Get(session *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { @@ -47,6 +48,10 @@ func (this *LogsManager) Get(session *mcclient.ClientSession, id string, params return IdentityLogs.Get(session, id, params) case apis.SERVICE_TYPE_CLOUDEVENT: return CloudeventLogs.Get(session, id, params) + case apis.SERVICE_TYPE_MONITOR: + return MonitorLogs.Get(session, id, params) + case apis.SERVICE_TYPE_NOTIFY: + return NotifyLogs.Get(session, id, params) default: return ComputeLogs.Get(session, id, params) } @@ -63,6 +68,10 @@ func (this *LogsManager) PerformClassAction(session *mcclient.ClientSession, act return IdentityLogs.PerformClassAction(session, action, params) case apis.SERVICE_TYPE_CLOUDEVENT: return CloudeventLogs.PerformClassAction(session, action, params) + case apis.SERVICE_TYPE_MONITOR: + return MonitorLogs.PerformClassAction(session, action, params) + case apis.SERVICE_TYPE_NOTIFY: + return NotifyLogs.PerformClassAction(session, action, params) default: return ComputeLogs.PerformClassAction(session, action, params) } @@ -88,6 +97,9 @@ func init() { MonitorLogs = NewMonitorV2Manager("event", "events", []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "tenant", "action", "notes"}, []string{}) + NotifyLogs = NewNotifyv2Manager("event", "events", + []string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "tenant", "action", "notes"}, + []string{}) Logs = LogsManager{ComputeLogs} Register(&Logs) diff --git a/pkg/mcclient/modules/notify/mod_notify.go b/pkg/mcclient/modules/notify/mod_notify.go index 17e353f7ee..9e395ed80d 100644 --- a/pkg/mcclient/modules/notify/mod_notify.go +++ b/pkg/mcclient/modules/notify/mod_notify.go @@ -62,7 +62,7 @@ func init() { Notification = modules.NewNotifyv2Manager( "notification", "notifications", - []string{"Title", "Content", "ContactType", "Priority", "Receiver_Details"}, + []string{"ID", "Name", "Contact_Type", "Title", "Content", "Priority", "Status", "Received_At", "Receiver_Type"}, []string{}, ) modules.Register(&Notification) diff --git a/pkg/notify/models/notification.go b/pkg/notify/models/notification.go index adae4123a0..fb607f50c1 100644 --- a/pkg/notify/models/notification.go +++ b/pkg/notify/models/notification.go @@ -521,7 +521,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", "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) s := rbacutils.TRbacScope(scope) switch s { diff --git a/pkg/notify/models/subscriber.go b/pkg/notify/models/subscriber.go index 8647566807..c4839b9bda 100644 --- a/pkg/notify/models/subscriber.go +++ b/pkg/notify/models/subscriber.go @@ -367,11 +367,11 @@ func (s *SSubscriber) CustomizeDelete(ctx context.Context, userCred mcclient.Tok return err } if s.Scope == string(rbacutils.ScopeSystem) { - if db.IsAdminAllowDelete(ctx, userCred, s) { + if !db.IsAdminAllowDelete(ctx, userCred, s) { return httperrors.NewForbiddenError("") } } else { - if db.IsDomainAllowDelete(ctx, userCred, s) { + if !db.IsDomainAllowDelete(ctx, userCred, s) { return httperrors.NewForbiddenError("") } if s.DomainId != userCred.GetProjectDomainId() { diff --git a/pkg/notify/models/topic.go b/pkg/notify/models/topic.go index 8a68ef4498..b70941a360 100644 --- a/pkg/notify/models/topic.go +++ b/pkg/notify/models/topic.go @@ -187,6 +187,7 @@ func (sm *STopicManager) InitializeData() error { notify.TOPIC_RESOURCE_SERVER, notify.TOPIC_RESOURCE_DBINSTANCE, notify.TOPIC_RESOURCE_ELASTICCACHE, + notify.TOPIC_RESOURCE_USER, ) t.addAction(notify.ActionUpdate) t.addAction(notify.ActionRebuildRoot) diff --git a/pkg/notify/tasks/notifications_send_task.go b/pkg/notify/tasks/notifications_send_task.go index 1e9c0bdfa3..5403c0ac19 100644 --- a/pkg/notify/tasks/notifications_send_task.go +++ b/pkg/notify/tasks/notifications_send_task.go @@ -155,6 +155,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 ...") continue }