mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
Merge pull request #12677 from zhaoxiangchun/automated-cherry-pick-of-#12671-upstream-release-3.8
Automated cherry pick of #12671: fix(monitor): 告警历史问题修复
This commit is contained in:
@@ -340,7 +340,7 @@ func (record *SAlertRecord) PostCreate(ctx context.Context, userCred mcclient.To
|
||||
log.Errorf("Reconcile from alert record error: %v", err)
|
||||
return
|
||||
}
|
||||
err = GetAlertResourceManager().NotifyAlertResourceCount(ctx)
|
||||
//err = GetAlertResourceManager().NotifyAlertResourceCount(ctx)
|
||||
if err != nil {
|
||||
log.Errorf("NotifyAlertResourceCount error: %v", err)
|
||||
return
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
mc_modules "yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
npk "yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
@@ -431,37 +430,30 @@ func (res *SAlertResource) CustomizeDelete(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SAlertResourceManager) NotifyAlertResourceCount(ctx context.Context) error {
|
||||
log.Errorln("exec NotifyAlertResourceCount func")
|
||||
cn, err := manager.getResourceCount()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
alertResourceCount := resourceCount{
|
||||
AlertResourceCount: cn,
|
||||
}
|
||||
if adminUsers == nil {
|
||||
manager.GetAdminRoleUsers(ctx, nil, true)
|
||||
}
|
||||
adminUsersTmp := *adminUsers
|
||||
ids := make([]string, 0)
|
||||
adminUsersTmp.Range(func(key, value interface{}) bool {
|
||||
ids = append(ids, key.(string))
|
||||
return true
|
||||
})
|
||||
if len(ids) == 0 {
|
||||
return fmt.Errorf("no find users in receivers has admin role")
|
||||
}
|
||||
//if len(ids) != 0 {
|
||||
// notifyclient.RawNotifyWithCtx(ctx, ids, false, npk.NotifyByWebConsole, npk.NotifyPriorityCritical,
|
||||
// "alertResourceCount", jsonutils.Marshal(&alertResourceCount))
|
||||
// return nil
|
||||
//} else {
|
||||
// return fmt.Errorf("no find users in receivers has admin role")
|
||||
//}
|
||||
manager.sendWebsocketInfo(ids, alertResourceCount)
|
||||
return nil
|
||||
}
|
||||
//func (manager *SAlertResourceManager) NotifyAlertResourceCount(ctx context.Context) error {
|
||||
// log.Errorln("exec NotifyAlertResourceCount func")
|
||||
// cn, err := manager.getResourceCount()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// alertResourceCount := resourceCount{
|
||||
// AlertResourceCount: cn,
|
||||
// }
|
||||
// if adminUsers == nil {
|
||||
// manager.GetAdminRoleUsers(ctx, nil, true)
|
||||
// }
|
||||
// adminUsersTmp := *adminUsers
|
||||
// ids := make([]string, 0)
|
||||
// adminUsersTmp.Range(func(key, value interface{}) bool {
|
||||
// ids = append(ids, key.(string))
|
||||
// return true
|
||||
// })
|
||||
// if len(ids) == 0 {
|
||||
// return fmt.Errorf("no find users in receivers has admin role")
|
||||
// }
|
||||
// //manager.sendWebsocketInfo(ids, alertResourceCount)
|
||||
// return nil
|
||||
//}
|
||||
|
||||
type resourceCount struct {
|
||||
AlertResourceCount int `json:"alert_resource_count"`
|
||||
@@ -518,7 +510,7 @@ func (manager *SAlertResourceManager) GetAdminRoleUsers(ctx context.Context, use
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *SAlertResourceManager) sendWebsocketInfo(uids []string, alertResourceCount resourceCount) {
|
||||
/*func (manager *SAlertResourceManager) sendWebsocketInfo(uids []string, alertResourceCount resourceCount) {
|
||||
session := auth.GetAdminSession(context.Background(), "", "")
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("obj_type", jsonutils.NewString("monitor"))
|
||||
@@ -537,4 +529,4 @@ func (manager *SAlertResourceManager) sendWebsocketInfo(uids []string, alertReso
|
||||
log.Errorf("websocket send info err:%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -1346,6 +1346,11 @@ jointLoop:
|
||||
continue jointLoop
|
||||
}
|
||||
}
|
||||
// 排除近期有报警状态的情况:system.uptime
|
||||
if joint.AlertState == monitor.MONITOR_RESOURCE_ALERT_STATUS_ALERTING && time.Now().Sub(joint.TriggerTime).
|
||||
Minutes() < 30 {
|
||||
continue
|
||||
}
|
||||
deleteJointIds = append(deleteJointIds, joint.RowId)
|
||||
}
|
||||
if len(resourceIds) == 0 {
|
||||
|
||||
@@ -299,7 +299,7 @@ func (self *SMonitorResource) RealDelete(ctx context.Context, userCred mcclient.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return self.SVirtualResourceBase.Delete(ctx, userCred)
|
||||
return self.SVirtualResourceBase.Delete(ctx, nil)
|
||||
}
|
||||
|
||||
func (self *SMonitorResource) DetachJoint(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
@@ -433,6 +433,13 @@ func (self *SMonitorResource) UpdateAttachJoint(alertRecord *SAlertRecord, match
|
||||
return errors.Wrapf(err, "SMonitorResource:%s UpdateAttachJoint err", self.Name)
|
||||
}
|
||||
errs := make([]error, 0)
|
||||
// 报警时发现没有进行关联,增加attach
|
||||
if len(joints) == 0 {
|
||||
self.AttachAlert(context.Background(), nil, alertRecord.AlertId)
|
||||
joints, _ = MonitorResourceAlertManager.GetJoinsByListInput(monitor.
|
||||
MonitorResourceJointListInput{MonitorResourceId: self.
|
||||
ResId, AlertId: alertRecord.AlertId})
|
||||
}
|
||||
for _, joint := range joints {
|
||||
err := joint.UpdateAlertRecordData(alertRecord, &match)
|
||||
if err != nil {
|
||||
|
||||
@@ -45,10 +45,11 @@ func (self *DetachAlertResourceTask) OnInit(ctx context.Context, obj db.IStandal
|
||||
self.taskFail(ctx, alert, msg)
|
||||
return
|
||||
}
|
||||
err := models.GetAlertResourceManager().NotifyAlertResourceCount(ctx)
|
||||
if err != nil {
|
||||
log.Errorf("DetachAlertResourceTask NotifyAlertResourceCount error:%v", err)
|
||||
}
|
||||
var err error
|
||||
//err := models.GetAlertResourceManager().NotifyAlertResourceCount(ctx)
|
||||
//if err != nil {
|
||||
// log.Errorf("DetachAlertResourceTask NotifyAlertResourceCount error:%v", err)
|
||||
//}
|
||||
// detach MonitorResourceJoint when alert disabel
|
||||
err = models.MonitorResourceAlertManager.DetachJoint(ctx, self.GetUserCred(),
|
||||
monitor.MonitorResourceJointListInput{AlertId: alert.GetId()})
|
||||
|
||||
Reference in New Issue
Block a user