Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
2084bca8
Commit
2084bca8
authored
Jul 04, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 完善预警规则设置字段
parent
3d628724
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
src/bean/vo/request/alert_rules.go
src/bean/vo/request/alert_rules.go
+6
-6
src/service/alert_rules.go
src/service/alert_rules.go
+8
-2
No files found.
src/bean/vo/request/alert_rules.go
View file @
2084bca8
...
...
@@ -24,21 +24,21 @@ type AddAlertRules struct {
}
type
UpdateAlertRules
struct
{
Id
string
`json:"id" binding:"required"`
Id
string
`json:"id"
form:"id"
binding:"required"`
MetricName
string
`json:"metric_name" form:"metric_name" binding:"required"`
// 预警规则名称(指标名称)
DetectionType
int
`json:"detection_type" form:"detection_type" binding:"oneof=1 2"`
// 检测类型 1:静态阈值 2:自定义
ClassId
int
`json:"class_id" form:"class_id" binding:"required
"`
// 预警对象id(级联:预警分类/预警对象)
ClassId
int
`json:"class_id" form:"class_id" binding:"required
_if=DetectionType 1"`
// 预警对象id(级联:预警分类/预警对象)
ClassParentName
string
`json:"class_parent_name" form:"class_parent_name" binding:"required_if=DetectionType 2"`
// 预警分类名称
ClassName
string
`json:"class_name" form:"class_name" binding:"required_if=DetectionType 2"`
// 预警对象名称
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name" binding:"required_if=DetectionType 2"`
// 预警指标名称(
detection_type=2时有值
)
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name" binding:"required_if=DetectionType 2"`
// 预警指标名称(
映射entity.MetricConfig.MetricName
)
Expr
string
`json:"expr" form:"expr" binding:"required_if=DetectionType 2"`
// 指标表达式(PromQL语句)
AlertCondition
[]
entity
.
AlertCondition
`json:"alert_condition" form:"alert_condition" binding:"required"`
// 预警规则 字典值
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type" binding:"required_if=DetectionType 2"`
// 预警规则类型 关联字典表
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" form:"alert_range"
`
// 预警范围 字典值
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" form:"alert_range"
binding:"required,dive"`
// 预警范围 字典值
Duration
int
`json:"duration" form:"duration" binding:"gte=0"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit" binding:"oneof=s m h"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"
gte=0"`
// 检查周期 单位:分钟
NotifyMethod
[]
string
`json:"notify_method" form:"notify_method" binding:"
oneof=all dingtalk sms"`
// 预警通知方式 all dingtalk sms
CheckPeriod
int
`json:"check_period" form:"check_period" binding:"
oneof=1 3 5 10 20 30"`
// 检查周期 单位:分钟
NotifyMethod
[]
string
`json:"notify_method" form:"notify_method" binding:"
max=2,dive,oneof=dingtalk sms"`
// 预警通知方式 all dingtalk sms
NotifyRecipients
[]
entity
.
NotifyRecipients
`json:"notify_recipients" form:"notify_recipients" binding:"dive"`
// 预警推送用户
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"`
// 消息推送频率 分钟
...
...
src/service/alert_rules.go
View file @
2084bca8
...
...
@@ -87,6 +87,9 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
_
,
err
=
session
.
Insert
(
&
data
)
return
nil
,
err
})
if
err
!=
nil
{
return
err
}
}
// TODO 告警规则添加到普罗米修斯表
...
...
@@ -118,7 +121,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
}
switch
req
.
DetectionType
{
case
1
:
_
,
err
=
db
.
Update
(
&
data
)
_
,
err
=
db
.
ID
(
data
.
Id
)
.
Update
(
&
data
)
if
err
!=
nil
{
return
err
}
...
...
@@ -161,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
})
if
err
!=
nil
{
return
err
}
}
return
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment