mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #12595 from zhaoxiangchun/bugfix/zxc-monitor
fix(monitor): monitor alert support:{level} filter
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
@@ -37,6 +39,7 @@ type AlertRecordShieldDetails struct {
|
||||
CommonAlertDetails
|
||||
AlertName string `json:"alert_name"`
|
||||
ResName string `json:"res_name"`
|
||||
Expired bool `json:"expired"`
|
||||
}
|
||||
|
||||
type AlertRecordShieldListInput struct {
|
||||
@@ -46,9 +49,11 @@ type AlertRecordShieldListInput struct {
|
||||
apis.EnabledResourceBaseListInput
|
||||
apis.StatusStandaloneResourceListInput
|
||||
|
||||
AlertName string `json:"alert_name"`
|
||||
ResType string `json:"res_type"`
|
||||
ResName string `json:"res_name"`
|
||||
ResId string `json:"res_id"`
|
||||
AlertId string `json:"alert_id"`
|
||||
AlertName string `json:"alert_name"`
|
||||
ResType string `json:"res_type"`
|
||||
ResName string `json:"res_name"`
|
||||
ResId string `json:"res_id"`
|
||||
AlertId string `json:"alert_id"`
|
||||
StartTime *time.Time `json:"start_time"`
|
||||
EndTime *time.Time `json:"end_time"`
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ type MonitorResourceJointListInput struct {
|
||||
ResType string `json:"res_type"`
|
||||
ResName string `json:"res_name"`
|
||||
AlertName string `json:"alert_name"`
|
||||
Level string `json:"level"`
|
||||
}
|
||||
|
||||
type MonitorResourceJointCreateInput struct {
|
||||
|
||||
@@ -358,7 +358,8 @@ func (f *sendBodyFactory) newSendnotify(evalCtx *alerting.EvalContext, notifier
|
||||
def.evalCtx = *evalCtx
|
||||
def.msg = message
|
||||
def.config = config
|
||||
if len(notifier.Setting.UserIds) == 0 {
|
||||
// 系统内置报警处理
|
||||
if len(notifier.Setting.UserIds) == 0 && len(notifier.Setting.RobotIds) == 0 {
|
||||
sys := new(sendSysImpl)
|
||||
sys.sendnotifyBase = def
|
||||
return sys
|
||||
|
||||
@@ -180,11 +180,15 @@ func (m *SMonitorResourceAlertManager) ListItemFilter(ctx context.Context, q *sq
|
||||
}
|
||||
q.Filter(sqlchemy.In(q.Field("monitor_resource_id"), resQ.SubQuery()))
|
||||
}
|
||||
alertQuery := CommonAlertManager.Query("id")
|
||||
if len(input.AlertName) != 0 {
|
||||
alertQuery := CommonAlertManager.Query("id")
|
||||
CommonAlertManager.FieldListFilter(alertQuery, monitor.CommonAlertListInput{Name: input.AlertName})
|
||||
q.Filter(sqlchemy.In(q.Field(m.GetSlaveFieldName()), alertQuery.SubQuery()))
|
||||
}
|
||||
if len(input.Level) != 0 {
|
||||
CommonAlertManager.FieldListFilter(alertQuery, monitor.CommonAlertListInput{Level: input.Level})
|
||||
q.Filter(sqlchemy.In(q.Field(m.GetSlaveFieldName()), alertQuery.SubQuery()))
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
@@ -238,8 +242,9 @@ func (obj *SMonitorResourceAlert) getMoreDetails(detail monitor.MonitorResourceJ
|
||||
}
|
||||
detail.AlertName = alert.Name
|
||||
|
||||
now := time.Now()
|
||||
shields, err := AlertRecordShieldManager.GetRecordShields(monitor.AlertRecordShieldListInput{ResId: obj.MonitorResourceId,
|
||||
AlertId: obj.AlertId})
|
||||
AlertId: obj.AlertId, EndTime: &now})
|
||||
if err != nil {
|
||||
log.Errorf("SMonitorResourceAlert get GetRecordShields by resId: %s,alertId: %s, err: %v",
|
||||
obj.MonitorResourceId, obj.AlertId, err)
|
||||
|
||||
@@ -133,6 +133,12 @@ func (manager *SAlertRecordShieldManager) shieldListByDetailsFeild(query *sqlche
|
||||
query.Join(resQuery, sqlchemy.Equals(query.Field("res_id"), resQuery.Field("res_id"))).Filter(sqlchemy.Equals(
|
||||
resQuery.Field("name"), input.ResName))
|
||||
}
|
||||
if input.StartTime != nil {
|
||||
query.Filter(sqlchemy.LE(query.Field("start_time"), input.StartTime))
|
||||
}
|
||||
if input.EndTime != nil {
|
||||
query.Filter(sqlchemy.GE(query.Field("end_time"), input.EndTime))
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -195,6 +201,9 @@ func (shield *SAlertRecordShield) GetMoreDetails(ctx context.Context, out monito
|
||||
if len(resources) == 0 {
|
||||
return out, nil
|
||||
}
|
||||
if shield.EndTime.Before(time.Now()) {
|
||||
out.Expired = true
|
||||
}
|
||||
out.ResName = resources[0].Name
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user