diff --git a/pkg/monitor/models/alertrecord.go b/pkg/monitor/models/alertrecord.go index 786af7724d..4a1b9a353d 100644 --- a/pkg/monitor/models/alertrecord.go +++ b/pkg/monitor/models/alertrecord.go @@ -340,6 +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) // if err != nil { // log.Errorf("NotifyAlertResourceCount error: %v", err) diff --git a/pkg/monitor/models/alertresource.go b/pkg/monitor/models/alertresource.go index f5c8619faf..f1278cf8b0 100644 --- a/pkg/monitor/models/alertresource.go +++ b/pkg/monitor/models/alertresource.go @@ -537,5 +537,4 @@ func (manager *SAlertResourceManager) sendWebsocketInfo(uids []string, alertReso log.Errorf("websocket send info err:%v", err) } } -} -*/ +}*/ diff --git a/pkg/monitor/models/commonalert.go b/pkg/monitor/models/commonalert.go index 7819c6047e..26e2e233bd 100644 --- a/pkg/monitor/models/commonalert.go +++ b/pkg/monitor/models/commonalert.go @@ -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 { diff --git a/pkg/monitor/models/monitor_resource.go b/pkg/monitor/models/monitor_resource.go index fa5bc59a88..a15ff39e6e 100644 --- a/pkg/monitor/models/monitor_resource.go +++ b/pkg/monitor/models/monitor_resource.go @@ -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 {