mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(monitor): detach alert (#20375)
This commit is contained in:
@@ -416,7 +416,20 @@ func (manager *SMonitorResourceManager) UpdateMonitorResourceAttachJoint(ctx con
|
||||
}
|
||||
deleteJointIds := make([]int64, 0)
|
||||
for _, joint := range resourceAlerts {
|
||||
if utils.IsInStringArray(joint.MonitorResourceId, matchResourceIds) {
|
||||
evalData, err := joint.GetData()
|
||||
if err != nil {
|
||||
log.Warningf("get data of monitor_resource_alert %s: %s", jsonutils.Marshal(joint), err)
|
||||
continue
|
||||
}
|
||||
metricName := evalData.Metric
|
||||
isMetricFound := false
|
||||
for _, match := range matches {
|
||||
if match.Metric == metricName {
|
||||
isMetricFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if utils.IsInStringArray(joint.MonitorResourceId, matchResourceIds) && isMetricFound {
|
||||
continue
|
||||
}
|
||||
deleteJointIds = append(deleteJointIds, joint.RowId)
|
||||
|
||||
@@ -152,6 +152,17 @@ func (obj *SMonitorResourceAlert) UpdateAlertRecordData(record *SAlertRecord, ma
|
||||
return nil
|
||||
}
|
||||
|
||||
func (obj *SMonitorResourceAlert) GetData() (*monitor.EvalMatch, error) {
|
||||
if obj.Data == nil {
|
||||
return nil, errors.Errorf("data is nil")
|
||||
}
|
||||
match := new(monitor.EvalMatch)
|
||||
if err := obj.Data.Unmarshal(match); err != nil {
|
||||
return nil, errors.Wrap(err, "unmarshal to monitor.EvalMatch")
|
||||
}
|
||||
return match, nil
|
||||
}
|
||||
|
||||
func (m *SMonitorResourceAlertManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input *monitor.MonitorResourceJointListInput) (*sqlchemy.SQuery, error) {
|
||||
var err error
|
||||
q, err = m.SJointResourceBaseManager.ListItemFilter(ctx, q, userCred, input.JointResourceBaseListInput)
|
||||
|
||||
Reference in New Issue
Block a user