Commit 72f4ba62 authored by 黄智's avatar 黄智

Merge remote-tracking branch 'origin/dev' into dev

parents dac54b71 2084bca8
...@@ -15,6 +15,7 @@ type AlertRules struct { ...@@ -15,6 +15,7 @@ type AlertRules struct {
DurationUnit string `json:"duration_unit" xorm:"'duration_unit'"` // 持续时间单位 s m h DurationUnit string `json:"duration_unit" xorm:"'duration_unit'"` // 持续时间单位 s m h
CheckPeriod int `json:"check_period" xorm:"'check_period'"` // 检查周期 单位:分钟 CheckPeriod int `json:"check_period" xorm:"'check_period'"` // 检查周期 单位:分钟
NotifyMethod string `json:"notify_method" xorm:"'notify_method'"` // 预警通知方式 all dingtalk sms NotifyMethod string `json:"notify_method" xorm:"'notify_method'"` // 预警通知方式 all dingtalk sms
NotifyRecipients string `json:"notify_recipients" xorm:"notify_recipients"` // 预警推送用户
NotifyPushCount int `json:"notify_push_count" xorm:"'notify_push_count'"` // 消息推送次数 NotifyPushCount int `json:"notify_push_count" xorm:"'notify_push_count'"` // 消息推送次数
NotifyPushFrequency int `json:"notify_push_frequency" xorm:"'notify_push_frequency'"` // 消息推送频率 分钟 NotifyPushFrequency int `json:"notify_push_frequency" xorm:"'notify_push_frequency'"` // 消息推送频率 分钟
IsEnabled int `json:"is_enabled" xorm:"'is_enabled'"` // 是否开启 0:关闭 1:启动 IsEnabled int `json:"is_enabled" xorm:"'is_enabled'"` // 是否开启 0:关闭 1:启动
...@@ -39,3 +40,9 @@ type AlertCondition struct { ...@@ -39,3 +40,9 @@ type AlertCondition struct {
ThresholdsMin int `json:"thresholds_min" form:"thresholds_min" binding:"required"` ThresholdsMin int `json:"thresholds_min" form:"thresholds_min" binding:"required"`
RiskLevel int `json:"risk_level" form:"risk_level" binding:"required"` RiskLevel int `json:"risk_level" form:"risk_level" binding:"required"`
} }
type NotifyRecipients struct {
SystemAccount string `json:"system_account" form:"system_account" binding:"required"`
Name string `json:"user_name" form:"user_name" binding:"required"`
Phone string `json:"phone" form:"phone" binding:"required"`
}
This diff is collapsed.
...@@ -4,6 +4,10 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" ...@@ -4,6 +4,10 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
type AlertRulesItem struct { type AlertRulesItem struct {
entity.AlertRules `xorm:"extends"` entity.AlertRules `xorm:"extends"`
AlertCondition []entity.AlertCondition `json:"alert_condition" form:"alert_condition" binding:"required"`
AlertRange []entity.RulesAlertRange `json:"alert_range" form:"alert_range" binding:"required,dive"`
NotifyMethod []string `json:"notify_method" form:"notify_method" binding:"max=2,dive,oneof=dingtalk sms"`
NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"`
} }
type AlertRulesList struct { type AlertRulesList struct {
......
...@@ -28,11 +28,14 @@ func (m *AlertClassSvc) Add(session *xorm.Session, req request.AddAlertClass) (c ...@@ -28,11 +28,14 @@ func (m *AlertClassSvc) Add(session *xorm.Session, req request.AddAlertClass) (c
} }
_ = copier.Copy(&data, &req) _ = copier.Copy(&data, &req)
max, err := m.SortOrderMax(data.ParentId) var max int
if err != nil { if data.SortOrder >= 0 {
return max, err = m.SortOrderMax(data.ParentId)
if err != nil {
return
}
data.SortOrder = max + 1
} }
data.SortOrder = max + 1
_, err = session.Insert(&data) _, err = session.Insert(&data)
classId = data.ClassId classId = data.ClassId
return return
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"xorm.io/xorm" "xorm.io/xorm"
) )
...@@ -31,9 +32,13 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error { ...@@ -31,9 +32,13 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
UpdatedAt: now, UpdatedAt: now,
} }
_ = copier.Copy(&data, &req) _ = copier.Copy(&data, &req)
data.AlertCondition = util.ConvertToString(req.AlertCondition)
data.AlertRange = util.ConvertToString(req.AlertRange)
data.NotifyMethod = util.ConvertToString(req.NotifyMethod)
data.NotifyRecipients = util.ConvertToString(req.NotifyRecipients)
switch req.DetectionType { switch req.DetectionType {
case 1: case 1:
_, err = db.Update(&data) _, err = db.Insert(&data)
if err != nil { if err != nil {
return err return err
} }
...@@ -82,6 +87,9 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error { ...@@ -82,6 +87,9 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
_, err = session.Insert(&data) _, err = session.Insert(&data)
return nil, err return nil, err
}) })
if err != nil {
return err
}
} }
// TODO 告警规则添加到普罗米修斯表 // TODO 告警规则添加到普罗米修斯表
...@@ -100,6 +108,10 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error { ...@@ -100,6 +108,10 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
UpdatedAt: now, UpdatedAt: now,
} }
_ = copier.Copy(&data, &req) _ = copier.Copy(&data, &req)
data.AlertCondition = util.ConvertToString(req.AlertCondition)
data.AlertRange = util.ConvertToString(req.AlertRange)
data.NotifyMethod = util.ConvertToString(req.NotifyMethod)
data.NotifyRecipients = util.ConvertToString(req.NotifyRecipients)
session := db.NewSession() session := db.NewSession()
var dbAlertRules entity.AlertRules var dbAlertRules entity.AlertRules
...@@ -109,7 +121,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error { ...@@ -109,7 +121,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
} }
switch req.DetectionType { switch req.DetectionType {
case 1: case 1:
_, err = db.Update(&data) _, err = db.ID(data.Id).Update(&data)
if err != nil { if err != nil {
return err return err
} }
...@@ -152,9 +164,12 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error { ...@@ -152,9 +164,12 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
} }
// 更新预警规则配置 // 更新预警规则配置
_, err = session.Update(&data) _, err = session.ID(data.Id).Update(&data)
return nil, err return nil, err
}) })
if err != nil {
return err
}
} }
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment