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
5ce39bee
Commit
5ce39bee
authored
Jul 05, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 完善预警规则设置列表
parent
dfddde9d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
34 deletions
+43
-34
src/bean/entity/alert_rules.go
src/bean/entity/alert_rules.go
+1
-1
src/bean/vo/request/alert_rules.go
src/bean/vo/request/alert_rules.go
+10
-19
src/bean/vo/response/alert_rules.go
src/bean/vo/response/alert_rules.go
+8
-4
src/service/alert_rules.go
src/service/alert_rules.go
+24
-10
No files found.
src/bean/entity/alert_rules.go
View file @
5ce39bee
...
@@ -32,7 +32,7 @@ func (m *AlertRules) TableName() string {
...
@@ -32,7 +32,7 @@ func (m *AlertRules) TableName() string {
type
RulesAlertRange
struct
{
type
RulesAlertRange
struct
{
Name
string
`json:"name" form:"name" binding:"required"`
Name
string
`json:"name" form:"name" binding:"required"`
Value
string
`json:"value" form:"value" binding:"required"`
Value
string
`json:"value" form:"value" binding:"required"`
Compare
string
`json:"compare" form:"compare" binding:"required"`
Compare
string
`json:"compare" form:"compare" binding:"required
,oneof== != =~ !~
"`
}
}
type
AlertCondition
struct
{
type
AlertCondition
struct
{
...
...
src/bean/vo/request/alert_rules.go
View file @
5ce39bee
package
request
package
request
import
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
import
(
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
)
type
AddAlertRules
struct
{
type
AddAlertRules
struct
{
MetricName
string
`json:"metric_name" form:"metric_name" binding:"required"`
// 预警规则名称(指标名称)
MetricName
string
`json:"metric_name" form:"metric_name" binding:"required"`
// 预警规则名称(指标名称)
...
@@ -55,23 +57,12 @@ type DetailAlertRules struct {
...
@@ -55,23 +57,12 @@ type DetailAlertRules struct {
}
}
type
ListAlertRules
struct
{
type
ListAlertRules
struct
{
Id
string
`json:"id" form:"id"`
// 请输入预警规则名称/预警对象/预警分类/预警指标
MetricName
string
`json:"metric_name" form:"metric_name"`
// 预警规则名称(指标名称)
Id
string
`json:"id" form:"id"`
DetectionType
int
`json:"detection_type" form:"detection_type"`
// 检测类型 1:静态阈值 2:自定义
NotifyMethod
string
`json:"notify_method" form:"notify_method" binding:"omitempty,oneof=all dingtalk sms"`
// 预警通知方式 all dingtalk sms
ClassId
int
`json:"class_id" form:"class_id"`
// 预警对象id(级联:预警分类/预警对象)
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=0 1 2"`
// 是否开启 1:是 2:否
ClassParentName
string
`json:"class_parent_name" form:"class_parent_name"`
// 预警分类名称
Keyword
string
`json:"keyword" form:"keyword"`
// 预警规则名称(指标名称)
ClassName
string
`json:"class_name" form:"class_name"`
// 预警对象名称
StartTime
string
`json:"start_time" form:"start_time"`
MetricConfigName
string
`json:"metric_config_name" form:"metric_config_name"`
// 预警指标名称(detection_type=2时有值)
EndTime
string
`json:"end_time" form:"end_time"`
Expr
string
`json:"expr" form:"expr"`
// 指标表达式(PromQL语句)
AlertCondition
string
`json:"alert_condition" form:"alert_condition"`
// 预警规则 字典值
AlertRuleType
string
`json:"alert_rule_type" form:"alert_rule_type"`
// 预警规则类型 关联字典表
AlertRange
string
`json:"alert_range" form:"alert_range"`
// 预警范围 字典值
Duration
int
`json:"duration" form:"duration"`
// 持续时间
DurationUnit
string
`json:"duration_unit" form:"duration_unit"`
// 持续时间单位 s m h
CheckPeriod
int
`json:"check_period" form:"check_period"`
// 检查周期 单位:分钟
NotifyMethod
string
`json:"notify_method" form:"notify_method"`
// 预警通知方式 all dingtalk sms
NotifyPushCount
int
`json:"notify_push_count" form:"notify_push_count"`
// 消息推送次数
NotifyPushFrequency
int
`json:"notify_push_frequency" form:"notify_push_frequency"`
// 消息推送频率 分钟
IsEnabled
int
`json:"is_enabled" form:"is_enabled"`
// 是否开启 1:是 2:否
Pagination
Pagination
}
}
src/bean/vo/response/alert_rules.go
View file @
5ce39bee
...
@@ -4,10 +4,14 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
...
@@ -4,10 +4,14 @@ 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"`
AlertCondition
[]
entity
.
AlertCondition
`json:"alert_condition" xorm:"alert_condition"`
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" form:"alert_range" binding:"required,dive"`
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" xorm:"alert_range"`
NotifyMethod
[]
string
`json:"notify_method" form:"notify_method" binding:"max=2,dive,oneof=dingtalk sms"`
NotifyMethod
[]
string
`json:"notify_method" xorm:"notify_method"`
NotifyRecipients
[]
entity
.
NotifyRecipients
`json:"notify_recipients" form:"notify_recipients" binding:"dive"`
NotifyRecipients
[]
entity
.
NotifyRecipients
`json:"notify_recipients" xorm:"notify_recipients"`
}
func
(
a
*
AlertRulesItem
)
TableName
()
string
{
return
"alert_rules"
}
}
type
AlertRulesList
struct
{
type
AlertRulesList
struct
{
...
...
src/service/alert_rules.go
View file @
5ce39bee
...
@@ -3,6 +3,7 @@ package service
...
@@ -3,6 +3,7 @@ package service
import
(
import
(
"github.com/google/uuid"
"github.com/google/uuid"
"github.com/jinzhu/copier"
"github.com/jinzhu/copier"
json
"github.com/json-iterator/go"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
...
@@ -183,27 +184,40 @@ func (m *AlertRulesSvc) GetDataById(req request.DetailAlertRules) (resp response
...
@@ -183,27 +184,40 @@ func (m *AlertRulesSvc) GetDataById(req request.DetailAlertRules) (resp response
return
return
}
}
func
(
m
*
AlertRulesSvc
)
List
(
req
request
.
ListAlertRules
)
(
resp
response
.
MetricConfig
List
,
err
error
)
{
func
(
m
*
AlertRulesSvc
)
List
(
req
request
.
ListAlertRules
)
(
resp
response
.
AlertRules
List
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
session
:=
db
.
NewSession
()
session
:=
db
.
NewSession
()
defer
session
.
Close
()
defer
session
.
Close
()
session
.
Table
(
new
(
entity
.
AlertRules
))
.
Alias
(
"r"
)
.
Select
(
"r.*"
)
session
.
Join
(
"LEFT"
,
"metric_config mc"
,
"mc.id = r.metric_config_id"
)
session
.
Join
(
"LEFT"
,
"alert_class ac"
,
"ac.class_id = r.class_id"
)
session
.
Join
(
"LEFT"
,
"alert_class acp"
,
"acp.class_id = ac.parent_id"
)
if
req
.
Id
!=
""
{
if
req
.
Id
!=
""
{
session
.
Where
(
"id = ?"
,
req
.
Id
)
session
.
Where
(
"
r.
id = ?"
,
req
.
Id
)
}
}
if
req
.
ClassId
!=
0
{
if
req
.
NotifyMethod
!=
""
&&
req
.
NotifyMethod
!=
"all"
{
session
.
Where
(
"
class_id = ?"
,
req
.
ClassId
)
session
.
Where
(
"
r.notify_method LIKE ?"
,
"%
\"
"
+
req
.
NotifyMethod
+
"
\"
%"
)
// ["dingtalk","sms"]
}
}
if
req
.
MetricName
!=
""
{
if
req
.
IsEnabled
>
0
{
session
.
Where
(
"
metric_name LIKE ?"
,
"%"
+
req
.
MetricName
+
"%"
)
session
.
Where
(
"
r.is_enabled = ?"
,
req
.
IsEnabled
)
}
}
if
req
.
IsEnabled
!=
0
{
if
req
.
Keyword
!=
""
{
session
.
Where
(
"is_enabled = ?"
,
req
.
IsEnabled
)
// 预警对象/预警分类/预警指标
session
.
Where
(
"r.metric_name LIKE ?"
,
"%"
+
req
.
Keyword
+
"%"
)
.
Or
(
"mc.metric_name LIKE ?"
,
"%"
+
req
.
Keyword
+
"%"
)
.
Or
(
"ac.class_name LIKE ?"
,
"%"
+
req
.
Keyword
+
"%"
)
.
Or
(
"acp.class_name LIKE ?"
,
"%"
+
req
.
Keyword
+
"%"
)
}
resp
.
TotalCount
,
err
=
session
.
Limit
(
req
.
GetPageSize
(),
(
req
.
GetPage
()
-
1
)
*
req
.
GetPageSize
())
.
FindAndCount
(
&
resp
.
List
)
for
i
:=
0
;
i
<
len
(
resp
.
List
);
i
++
{
_
=
json
.
Unmarshal
([]
byte
(
resp
.
List
[
i
]
.
AlertRules
.
AlertCondition
),
&
resp
.
List
[
i
]
.
AlertCondition
)
_
=
json
.
Unmarshal
([]
byte
(
resp
.
List
[
i
]
.
AlertRules
.
AlertRange
),
&
resp
.
List
[
i
]
.
AlertRange
)
_
=
json
.
Unmarshal
([]
byte
(
resp
.
List
[
i
]
.
AlertRules
.
NotifyMethod
),
&
resp
.
List
[
i
]
.
NotifyMethod
)
_
=
json
.
Unmarshal
([]
byte
(
resp
.
List
[
i
]
.
AlertRules
.
NotifyRecipients
),
&
resp
.
List
[
i
]
.
NotifyRecipients
)
}
}
resp
.
TotalCount
,
err
=
session
.
Table
(
new
(
entity
.
AlertRules
))
.
Limit
(
req
.
GetPageSize
(),
(
req
.
GetPage
()
-
1
)
*
req
.
GetPageSize
())
.
OrderBy
(
"id"
)
.
FindAndCount
(
&
resp
.
List
)
return
return
}
}
...
...
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