Commit 2b39353a authored by 李科's avatar 李科

fix: 完善预警规则设置参数

parent d5d5cf64
...@@ -30,9 +30,10 @@ func (m *AlertRules) TableName() string { ...@@ -30,9 +30,10 @@ func (m *AlertRules) TableName() string {
} }
type RulesAlertRange struct { type RulesAlertRange struct {
Name string `json:"name" form:"name" binding:"required"` ChineseName string `json:"chinese_name" binding:"required"`
Value string `json:"value" form:"value" binding:"required"` Name string `json:"name" form:"name" binding:"required"`
Compare string `json:"compare" form:"compare" binding:"required,oneof== != =~ !~"` Value string `json:"value" form:"value" binding:"required"`
Compare string `json:"compare" form:"compare" binding:"required,oneof== != =~ !~"`
} }
type AlertCondition struct { type AlertCondition struct {
...@@ -43,6 +44,6 @@ type AlertCondition struct { ...@@ -43,6 +44,6 @@ type AlertCondition struct {
type NotifyRecipients struct { type NotifyRecipients struct {
SystemAccount string `json:"system_account" form:"system_account" binding:"required"` SystemAccount string `json:"system_account" form:"system_account" binding:"required"`
Name string `json:"user_name" form:"user_name" binding:"required"` UserName string `json:"user_name" form:"user_name" binding:"required"`
Phone string `json:"phone" form:"phone" binding:"required"` Phone string `json:"phone" form:"phone" binding:"required"`
} }
...@@ -23,7 +23,7 @@ type AddAlertRules struct { ...@@ -23,7 +23,7 @@ type AddAlertRules struct {
NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"` // 预警推送用户 NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"` // 预警推送用户
NotifyPushCount int `json:"notify_push_count" form:"notify_push_count" binding:"gte=1"` // 消息推送次数 NotifyPushCount int `json:"notify_push_count" form:"notify_push_count" binding:"gte=1"` // 消息推送次数
NotifyPushFrequency int `json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"` // 消息推送频率 分钟 NotifyPushFrequency int `json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"` // 消息推送频率 分钟
IsEnabled int `json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"` // 是否开启 1:是 2:否 IsEnabled int `json:"is_enabled" form:"is_enabled" binding:"oneof=1 2"` // 是否开启 1:是 2:否
} }
type UpdateAlertRules struct { type UpdateAlertRules struct {
...@@ -46,7 +46,12 @@ type UpdateAlertRules struct { ...@@ -46,7 +46,12 @@ type UpdateAlertRules struct {
NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"` // 预警推送用户 NotifyRecipients []entity.NotifyRecipients `json:"notify_recipients" form:"notify_recipients" binding:"dive"` // 预警推送用户
NotifyPushCount int `json:"notify_push_count" form:"notify_push_count" binding:"gte=1"` // 消息推送次数 NotifyPushCount int `json:"notify_push_count" form:"notify_push_count" binding:"gte=1"` // 消息推送次数
NotifyPushFrequency int `json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"` // 消息推送频率 分钟 NotifyPushFrequency int `json:"notify_push_frequency" form:"notify_push_frequency" binding:"gte=1"` // 消息推送频率 分钟
IsEnabled int `json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"` // 是否开启 1:是 2:否 IsEnabled int `json:"is_enabled" form:"is_enabled" binding:"oneof=1 2"` // 是否开启 1:是 2:否
}
type UpdateIsEnabledAlertRules struct {
Id string `json:"id" form:"id" binding:"required"`
IsEnabled int `json:"is_enabled" form:"is_enabled" binding:"oneof=1 2"` // 是否开启 1:是 2:否
} }
type DeleteAlertRules struct { type DeleteAlertRules struct {
......
...@@ -42,6 +42,23 @@ func UpdateAlertRules(c *gin.Context) { ...@@ -42,6 +42,23 @@ func UpdateAlertRules(c *gin.Context) {
SendJsonResponse(c, resp.OK, nil) SendJsonResponse(c, resp.OK, nil)
} }
func UpdateIsEnabledAlertRules(c *gin.Context) {
var req request.UpdateIsEnabledAlertRules
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil)
return
}
svc := service.AlertRulesSvc{User: header.GetUser(c)}
err := svc.UpdateIsEnabled(req)
if err != nil {
SendJsonResponse(c, resp.FAIL.WithError(err), nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
func DeleteAlertRules(c *gin.Context) { func DeleteAlertRules(c *gin.Context) {
var req request.DeleteAlertRules var req request.DeleteAlertRules
if err := c.ShouldBind(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
......
...@@ -13,6 +13,7 @@ func InitAlertRulesRouter(e *gin.Engine) { ...@@ -13,6 +13,7 @@ func InitAlertRulesRouter(e *gin.Engine) {
{ {
group.POST("", controller.AddAlertRules) group.POST("", controller.AddAlertRules)
group.PUT("", controller.UpdateAlertRules) group.PUT("", controller.UpdateAlertRules)
group.PUT("is_enabled", controller.UpdateIsEnabledAlertRules)
group.DELETE("", controller.DeleteAlertRules) group.DELETE("", controller.DeleteAlertRules)
group.GET("", controller.DetailAlertRules) group.GET("", controller.DetailAlertRules)
group.GET("list", controller.ListAlertRules) group.GET("list", controller.ListAlertRules)
......
...@@ -115,6 +115,7 @@ func (a *AlertRulesSvc) Update(req request.UpdateAlertRules) error { ...@@ -115,6 +115,7 @@ func (a *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
data.NotifyRecipients = util.ConvertToString(req.NotifyRecipients) data.NotifyRecipients = util.ConvertToString(req.NotifyRecipients)
session := db.NewSession() session := db.NewSession()
defer session.Close()
var dbAlertRules entity.AlertRules var dbAlertRules entity.AlertRules
_, err = session.Table(data.TableName()).ID(data.Id).Get(&dbAlertRules) _, err = session.Table(data.TableName()).ID(data.Id).Get(&dbAlertRules)
if err != nil { if err != nil {
...@@ -175,6 +176,25 @@ func (a *AlertRulesSvc) Update(req request.UpdateAlertRules) error { ...@@ -175,6 +176,25 @@ func (a *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
return nil return nil
} }
func (a *AlertRulesSvc) UpdateIsEnabled(req request.UpdateIsEnabledAlertRules) error {
db, err := client.GetDbClient()
if err != nil {
err = resp.DbConnectError.WithError(err)
return err
}
now := jsontime.Now()
data := entity.AlertRules{
Id: req.Id,
IsEnabled: req.IsEnabled,
UpdatedBy: a.User.SystemAccount,
UpdatedAt: now,
}
session := db.NewSession()
defer session.Close()
_, err = session.Table(data.TableName()).Cols("is_enabled,updated_by,updated_at").Where("id = ?", req.Id).Update(&data)
return err
}
func (a *AlertRulesSvc) GetDataById(req request.DetailAlertRules) (resp response.AlertRulesItem, err error) { func (a *AlertRulesSvc) GetDataById(req request.DetailAlertRules) (resp response.AlertRulesItem, err error) {
list, err := a.List(request.ListAlertRules{Id: req.Id}) list, err := a.List(request.ListAlertRules{Id: req.Id})
if err != nil { if err != 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