mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #5542 from zexi/automated-cherry-pick-of-#5541-upstream-release-3.1
Automated cherry pick of #5541: monitor: fix meteralert update status
This commit is contained in:
@@ -70,4 +70,5 @@ type MeterAlertUpdateInput struct {
|
||||
ProjectId *string `json:"project_id"`
|
||||
// 通知方式, 比如: email, mobile
|
||||
Channel *string `json:"channel"`
|
||||
Status *string `json:"status"`
|
||||
}
|
||||
|
||||
@@ -171,6 +171,7 @@ type AlertV1Details struct {
|
||||
Measurement string `json:"measurement"`
|
||||
Field string `json:"field"`
|
||||
NotifierId string `json:"notifier_id"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type NodeAlertDetails struct {
|
||||
|
||||
@@ -570,6 +570,12 @@ func (alert *SMeterAlert) getUpdateSetting(details monitor.MeterAlertDetails, ds
|
||||
return out.Settings
|
||||
}
|
||||
|
||||
func (alert *SMeterAlert) PostUpdate(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
alert.SV1Alert.PostUpdate(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (alert *SMeterAlert) CustomizeDelete(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
|
||||
@@ -292,6 +292,15 @@ func (alert *SV1Alert) CustomizeCreate(
|
||||
return err
|
||||
}
|
||||
|
||||
func (alert *SV1Alert) PostUpdate(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
if data.(*jsonutils.JSONDict).Contains("status") {
|
||||
status, _ := data.(*jsonutils.JSONDict).GetString("status")
|
||||
alert.UpdateIsEnabledStatus(ctx, userCred, &status)
|
||||
}
|
||||
}
|
||||
|
||||
func (alert *SNodeAlert) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
if err := alert.SVirtualResourceBase.CustomizeCreate(ctx, userCred, ownerId, query, data); err != nil {
|
||||
return err
|
||||
@@ -353,6 +362,18 @@ func (alert *SNodeAlert) PostCreate(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
V1AlertDisabledStatus = "Disabled"
|
||||
V1AlertEnabledStatus = "Enabled"
|
||||
)
|
||||
|
||||
func (alert *SV1Alert) GetStatus() string {
|
||||
if alert.IsEnable() {
|
||||
return V1AlertEnabledStatus
|
||||
}
|
||||
return V1AlertDisabledStatus
|
||||
}
|
||||
|
||||
func (alert *SV1Alert) GetExtraDetails(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
@@ -414,6 +435,7 @@ func (alert *SV1Alert) GetExtraDetails(
|
||||
out.Measurement = measurement
|
||||
out.Field = field
|
||||
out.DB = db
|
||||
out.Status = alert.GetStatus()
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -483,6 +505,33 @@ func (alert *SV1Alert) UpdateNotification(usedBy string, channel, recipients *st
|
||||
return err
|
||||
}
|
||||
|
||||
func (alert *SV1Alert) UpdateIsEnabledStatus(ctx context.Context, userCred mcclient.TokenCredential, status *string) error {
|
||||
if status == nil {
|
||||
return nil
|
||||
}
|
||||
if status != nil {
|
||||
s := *status
|
||||
if s == V1AlertDisabledStatus {
|
||||
if _, err := alert.PerformDisable(ctx, userCred, nil, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
db.Update(&alert.SAlert, func() error {
|
||||
alert.SetStatus(userCred, V1AlertDisabledStatus, "")
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
if _, err := alert.PerformEnable(ctx, userCred, nil, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
db.Update(&alert.SAlert, func() error {
|
||||
alert.SetStatus(userCred, V1AlertEnabledStatus, "")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (alert *SV1Alert) CustomizeDelete(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
@@ -628,6 +677,12 @@ func (alert *SNodeAlert) getUpdateSetting(
|
||||
return out.Settings
|
||||
}
|
||||
|
||||
func (alert *SNodeAlert) PostUpdate(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
alert.SV1Alert.PostUpdate(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (alert *SNodeAlert) CustomizeDelete(
|
||||
ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
|
||||
Reference in New Issue
Block a user