diff --git a/pkg/apis/monitor/monitor_resource.go b/pkg/apis/monitor/monitor_resource.go index 4bceec7c2a..94629afeed 100644 --- a/pkg/apis/monitor/monitor_resource.go +++ b/pkg/apis/monitor/monitor_resource.go @@ -42,6 +42,8 @@ type MonitorResourceListInput struct { ResId []string `json:"res_id"` ResType string `json:"res_type"` OnlyResId bool `json:"only_res_id"` + + ResName string `json:"res_name"` } type MonitorResourceDetails struct { diff --git a/pkg/apis/monitor/monitor_resource_alert.go b/pkg/apis/monitor/monitor_resource_alert.go index a7da675e94..4a52de494b 100644 --- a/pkg/apis/monitor/monitor_resource_alert.go +++ b/pkg/apis/monitor/monitor_resource_alert.go @@ -30,6 +30,7 @@ type MonitorResourceJointListInput struct { Alerting bool `json:"alertinng"` SendState string `json:"send_state"` ResType string `json:"res_type"` + ResName string `json:"res_name"` } type MonitorResourceJointCreateInput struct { diff --git a/pkg/monitor/models/modelset.go b/pkg/monitor/models/modelset.go index 3835f0591e..bb99006b66 100644 --- a/pkg/monitor/models/modelset.go +++ b/pkg/monitor/models/modelset.go @@ -63,6 +63,7 @@ type Details struct { DomainId string ProjectDomain string Ips string + Account string } type Guest struct { compute_models.SGuest diff --git a/pkg/monitor/models/monitor_resource.go b/pkg/monitor/models/monitor_resource.go index d67a324fd7..0e960cbccc 100644 --- a/pkg/monitor/models/monitor_resource.go +++ b/pkg/monitor/models/monitor_resource.go @@ -192,6 +192,9 @@ func (manager *SMonitorResourceManager) FieldListFilter(q *sqlchemy.SQuery, quer if len(query.ResId) != 0 { q.In("res_id", query.ResId) } + if len(query.ResName) != 0 { + q.Equals("name", query.ResName) + } return q } diff --git a/pkg/monitor/models/monitor_resource_alert.go b/pkg/monitor/models/monitor_resource_alert.go index 0fa6dba6d2..fbd69df25d 100644 --- a/pkg/monitor/models/monitor_resource_alert.go +++ b/pkg/monitor/models/monitor_resource_alert.go @@ -171,6 +171,15 @@ func (m *SMonitorResourceAlertManager) ListItemFilter(ctx context.Context, q *sq if len(input.ResType) != 0 { q.Equals("res_type", input.ResType) } + if len(input.ResName) != 0 { + resQ := MonitorResourceManager.Query("res_id") + resQ, err = MonitorResourceManager.ListItemFilter(ctx, resQ, userCred, + monitor.MonitorResourceListInput{ResName: input.ResName}) + if err != nil { + return q, errors.Wrap(err, "Get monitor in Query err") + } + q.Filter(sqlchemy.In(q.Field("monitor_resource_id"), resQ.SubQuery())) + } return q, nil } diff --git a/pkg/monitor/models/recordshield.go b/pkg/monitor/models/recordshield.go index 60d92c444b..cb01913478 100644 --- a/pkg/monitor/models/recordshield.go +++ b/pkg/monitor/models/recordshield.go @@ -32,6 +32,10 @@ import ( "yunion.io/x/onecloud/pkg/util/stringutils2" ) +const ( + DEFAULT_SHEILD_TIME = 100 // year +) + var ( AlertRecordShieldManager *SAlertRecordShieldManager ) @@ -223,6 +227,12 @@ func (man *SAlertRecordShieldManager) ValidateCreateData(ctx context.Context, us } data.ResType = resources[0].ResType } + if len(data.StartTime) == 0 { + data.StartTime = time.Now().UTC().Format(timeutils.MysqlTimeFormat) + } + if len(data.EndTime) == 0 { + data.EndTime = time.Now().AddDate(DEFAULT_SHEILD_TIME, 0, 0).UTC().Format(timeutils.MysqlTimeFormat) + } startTime, err := timeutils.ParseTimeStr(data.StartTime) if err != nil { return data, httperrors.NewInputParameterError("parse start_time: %s err", data.StartTime)