mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #12314 from zhaoxiangchun/feature/zxc-monitor_sheild_master
fix(monitor): monitor shield fix
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -63,6 +63,7 @@ type Details struct {
|
||||
DomainId string
|
||||
ProjectDomain string
|
||||
Ips string
|
||||
Account string
|
||||
}
|
||||
type Guest struct {
|
||||
compute_models.SGuest
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user