diff --git a/pkg/apis/monitor/alert.go b/pkg/apis/monitor/alert.go index b1a36be26f..1140f85a91 100644 --- a/pkg/apis/monitor/alert.go +++ b/pkg/apis/monitor/alert.go @@ -121,8 +121,9 @@ type AlertUpdateInput struct { // 报警设置 Settings *AlertSetting `json:"settings"` // 启用报警 - Enabled *bool `json:"enabled"` - Message *string `json:"message"` + Enabled *bool `json:"enabled"` + // 报警级别 + Level *string `json:"level"` } type AlertListInput struct { diff --git a/pkg/monitor/models/alert.go b/pkg/monitor/models/alert.go index 7eb0903676..47f8b79afb 100644 --- a/pkg/monitor/models/alert.go +++ b/pkg/monitor/models/alert.go @@ -21,7 +21,6 @@ import ( "time" "yunion.io/x/jsonutils" - "yunion.io/x/log" "yunion.io/x/pkg/errors" "yunion.io/x/sqlchemy" @@ -79,7 +78,7 @@ type SAlert struct { Frequency int64 `nullable:"false" list:"user" create:"required" update:"user"` Settings jsonutils.JSONObject `nullable:"false" list:"user" create:"required" update:"user"` - Level string `charset:"ascii" width:"36"nullable:"false" default:"normal" list:"user"` + Level string `charset:"ascii" width:"36"nullable:"false" default:"normal" list:"user" update:"user"` Message string `charset:"utf8" list:"user" update:"user"` UsedBy string `charset:"ascii" list:"user"` @@ -312,30 +311,17 @@ func (alert *SAlert) SetState(input AlertSetStateInput) error { func (alert *SAlert) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input monitor.AlertUpdateInput) (*jsonutils.JSONDict, error) { if input.Settings != nil { - if err := jsonutils.Update(alert.Settings, jsonutils.Marshal(input.Settings)); err != nil { - return nil, err - } - if err := jsonutils.Update(input.Settings, alert.Settings); err != nil { + updateSettings := jsonutils.NewDict() + updateSettings.Update(alert.Settings) + updateSettings.Update(jsonutils.Marshal(input.Settings)) + input.Settings = new(monitor.AlertSetting) + if err := updateSettings.Unmarshal(input.Settings); err != nil { return nil, err } } return alert.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, input.JSON(input)) } -func (alert *SAlert) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { - input := new(monitor.AlertUpdateInput) - if err := data.Unmarshal(input); err != nil { - log.Errorf("update unmarshal error: %v", err) - return - } - if _, err := db.Update(alert, func() error { - alert.Settings = jsonutils.Marshal(input) - return nil - }); err != nil { - log.Errorf("update setting error: %v", err) - } -} - func (alert *SAlert) IsAttachNotification(noti *SNotification) (bool, error) { q := AlertNotificationManager.Query().Equals("notification_id", noti.GetId()).Equals("alert_id", alert.GetId()) cnt, err := q.CountWithError() diff --git a/pkg/monitor/models/nodealert.go b/pkg/monitor/models/nodealert.go index de83601320..51dff052e4 100644 --- a/pkg/monitor/models/nodealert.go +++ b/pkg/monitor/models/nodealert.go @@ -547,6 +547,7 @@ func (alert *SNodeAlert) ValidateUpdateData( } if input.Level != nil && *input.Level != details.Level { details.Level = *input.Level + ret.Level = input.Level } if input.Window != nil && *input.Window != details.Window {