mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
detach AlertResource on alertDisable
1. 报警规则禁用时,detach 关联的报警资源 影响范围:报警规则的禁用;logger日志服务i18n的日志展示
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/monitor/models"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
type DetachAlertResourceTask struct {
|
||||
taskman.STask
|
||||
}
|
||||
|
||||
func init() {
|
||||
taskman.RegisterTask(&DetachAlertResourceTask{})
|
||||
}
|
||||
|
||||
func (self *DetachAlertResourceTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
|
||||
alert := obj.(*models.SCommonAlert)
|
||||
errs := alert.DetachAlertResourceOnDisable(ctx, self.GetUserCred())
|
||||
if len(errs) != 0 {
|
||||
msg := jsonutils.NewString(fmt.Sprintf("fail to DetachAlertResourceOnAlertDisable:%s.err:%v", alert.Name, errors.NewAggregate(errs)))
|
||||
self.taskFail(ctx, alert, msg)
|
||||
return
|
||||
}
|
||||
err := models.GetAlertResourceManager().NotifyAlertResourceCount(ctx)
|
||||
if err != nil {
|
||||
log.Errorf("DetachAlertResourceTask NotifyAlertResourceCount error:%v", err)
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, alert, logclient.ACT_DETACH_ALERTRESOURCE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *DetachAlertResourceTask) taskFail(ctx context.Context, alert *models.SCommonAlert, msg jsonutils.JSONObject) {
|
||||
db.OpsLog.LogEvent(alert, db.ACT_DETACH, msg, self.GetUserCred())
|
||||
logclient.AddActionLogWithStartable(self, alert, logclient.ACT_DETACH_ALERTRESOURCE, msg, self.UserCred, false)
|
||||
self.SetStageFailed(ctx, msg)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user