diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 2972098f76..ca7344983f 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -2886,10 +2886,12 @@ func (self *SGuest) PerformChangeBandwidth(ctx context.Context, userCred mcclien guestnics := self.GetNetworks() index, err := data.Int("index") if err != nil || index > int64(len(guestnics)) { + logclient.AddActionLog(self, logclient.ACT_VM_CHANGE_BANDWIDTH, "Index Not fount or out of NIC index", userCred, false) return nil, httperrors.NewBadRequestError("Index Not fount or out of NIC index") } bandwidth, err := data.Int("bandwidth") if err != nil || bandwidth <= 0 { + logclient.AddActionLog(self, logclient.ACT_VM_CHANGE_BANDWIDTH, "Bandwidth must be larger than 0", userCred, false) return nil, httperrors.NewBadRequestError("Bandwidth must be larger than 0") } guestnic := &guestnics[index] @@ -2899,11 +2901,14 @@ func (self *SGuest) PerformChangeBandwidth(ctx context.Context, userCred mcclien return nil }) err := self.StartSyncTask(ctx, userCred, false, "") + logclient.AddActionLog(self, logclient.ACT_VM_CHANGE_BANDWIDTH, err, userCred, err == nil) return nil, err } return nil, nil } - return nil, httperrors.NewBadRequestError("Cannot change bandwidth in status %s", self.Status) + msg := fmt.Sprintf("Cannot change bandwidth in status %s", self.Status) + logclient.AddActionLog(self, logclient.ACT_VM_CHANGE_BANDWIDTH, msg, userCred, false) + return nil, httperrors.NewBadRequestError(msg) } func (self *SGuest) AllowPerformChangeConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/util/logclient/logclient.go b/pkg/util/logclient/logclient.go index 655d9ab0cb..0d8a541788 100644 --- a/pkg/util/logclient/logclient.go +++ b/pkg/util/logclient/logclient.go @@ -48,6 +48,7 @@ const ( ACT_VM_PURGE = "清除" ACT_VM_REBUILD = "重装系统" ACT_VM_RESET_PSWD = "重置密码" + ACT_VM_CHANGE_BANDWIDTH = "调整带宽" ACT_VM_START = "开机" ACT_VM_STOP = "关机" ACT_VM_RESTART = "重启" @@ -56,6 +57,9 @@ const ( ACT_VM_UNBIND_KEYPAIR = "解绑密钥" ) +// golang 不支持 const 的string array, http://t.cn/EzAvbw8 +var BLACK_LIST_OBJ_TYPE = []string{"parameter"} + var logclientWorkerMan *appsrv.WorkerManager func init() { @@ -73,7 +77,13 @@ func AddActionLog(model IObject, action string, iNotes interface{}, userCred mcc token := userCred notes := stringutils.Interface2String(iNotes) - // s := auth.GetSession(userCred, "", "") + // 忽略不黑名单里的资源类型 + for _, v := range BLACK_LIST_OBJ_TYPE { + if v == model.Keyword() { + log.Errorf("不支持的 actionlog 类型") + return + } + } objId := model.GetId() if len(objId) == 0 {