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
6a02848b
Commit
6a02848b
authored
Jul 05, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 完善预警规则设置列表
parent
5ce39bee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
30 deletions
+41
-30
src/bean/vo/request/alert_rules.go
src/bean/vo/request/alert_rules.go
+2
-2
src/bean/vo/response/alert_rules.go
src/bean/vo/response/alert_rules.go
+3
-0
src/service/alert_class.go
src/service/alert_class.go
+12
-12
src/service/alert_rules.go
src/service/alert_rules.go
+23
-15
src/service/prometheus.go
src/service/prometheus.go
+1
-1
No files found.
src/bean/vo/request/alert_rules.go
View file @
6a02848b
...
@@ -62,7 +62,7 @@ type ListAlertRules struct {
...
@@ -62,7 +62,7 @@ type ListAlertRules struct {
NotifyMethod
string
`json:"notify_method" form:"notify_method" binding:"omitempty,oneof=all dingtalk sms"`
// 预警通知方式 all dingtalk sms
NotifyMethod
string
`json:"notify_method" form:"notify_method" binding:"omitempty,oneof=all dingtalk sms"`
// 预警通知方式 all dingtalk sms
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:"omitempty,oneof=0 1 2"`
// 是否开启 1:是 2:否
Keyword
string
`json:"keyword" form:"keyword"`
// 预警规则名称(指标名称)
Keyword
string
`json:"keyword" form:"keyword"`
// 预警规则名称(指标名称)
StartTime
string
`json:"start_time" form:"start_time"`
StartTime
string
`json:"start_time" form:"start_time"
binding:"omitempty,datetime=2006-01-02 15:04:05"
`
EndTime
string
`json:"end_time" form:"end_time"`
EndTime
string
`json:"end_time" form:"end_time"
binding:"omitempty,datetime=2006-01-02 15:04:05"
`
Pagination
Pagination
}
}
src/bean/vo/response/alert_rules.go
View file @
6a02848b
...
@@ -4,6 +4,9 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
...
@@ -4,6 +4,9 @@ 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"`
ClassParentName
string
`json:"class_parent_name" xorm:"class_parent_name"`
ClassName
string
`json:"class_name" xorm:"class_name"`
MetricConfigName
string
`json:"metric_config_name" xorm:"metric_config_name"`
AlertCondition
[]
entity
.
AlertCondition
`json:"alert_condition" xorm:"alert_condition"`
AlertCondition
[]
entity
.
AlertCondition
`json:"alert_condition" xorm:"alert_condition"`
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" xorm:"alert_range"`
AlertRange
[]
entity
.
RulesAlertRange
`json:"alert_range" xorm:"alert_range"`
NotifyMethod
[]
string
`json:"notify_method" xorm:"notify_method"`
NotifyMethod
[]
string
`json:"notify_method" xorm:"notify_method"`
...
...
src/service/alert_class.go
View file @
6a02848b
...
@@ -18,19 +18,19 @@ type AlertClassSvc struct {
...
@@ -18,19 +18,19 @@ type AlertClassSvc struct {
User
entity
.
SystemUserInfo
User
entity
.
SystemUserInfo
}
}
func
(
m
*
AlertClassSvc
)
Add
(
session
*
xorm
.
Session
,
req
request
.
AddAlertClass
)
(
classId
int
,
err
error
)
{
func
(
a
*
AlertClassSvc
)
Add
(
session
*
xorm
.
Session
,
req
request
.
AddAlertClass
)
(
classId
int
,
err
error
)
{
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertClass
{
data
:=
entity
.
AlertClass
{
CreatedBy
:
m
.
User
.
SystemAccount
,
CreatedBy
:
a
.
User
.
SystemAccount
,
CreatedAt
:
now
,
CreatedAt
:
now
,
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
var
max
int
var
max
int
if
data
.
SortOrder
>=
0
{
if
data
.
SortOrder
>=
0
{
max
,
err
=
m
.
SortOrderMax
(
data
.
ParentId
)
max
,
err
=
a
.
SortOrderMax
(
data
.
ParentId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
@@ -41,10 +41,10 @@ func (m *AlertClassSvc) Add(session *xorm.Session, req request.AddAlertClass) (c
...
@@ -41,10 +41,10 @@ func (m *AlertClassSvc) Add(session *xorm.Session, req request.AddAlertClass) (c
return
return
}
}
func
(
m
*
AlertClassSvc
)
Update
(
session
*
xorm
.
Session
,
req
request
.
UpdateAlertClass
)
error
{
func
(
a
*
AlertClassSvc
)
Update
(
session
*
xorm
.
Session
,
req
request
.
UpdateAlertClass
)
error
{
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertClass
{
data
:=
entity
.
AlertClass
{
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
...
@@ -55,7 +55,7 @@ func (m *AlertClassSvc) Update(session *xorm.Session, req request.UpdateAlertCla
...
@@ -55,7 +55,7 @@ func (m *AlertClassSvc) Update(session *xorm.Session, req request.UpdateAlertCla
return
nil
return
nil
}
}
func
(
m
*
AlertClassSvc
)
Move
(
req
request
.
MoveAlertClass
)
(
err
error
)
{
func
(
a
*
AlertClassSvc
)
Move
(
req
request
.
MoveAlertClass
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
err
=
resp
.
DbConnectError
.
WithError
(
err
)
...
@@ -123,7 +123,7 @@ func (m *AlertClassSvc) Move(req request.MoveAlertClass) (err error) {
...
@@ -123,7 +123,7 @@ func (m *AlertClassSvc) Move(req request.MoveAlertClass) (err error) {
return
nil
return
nil
}
}
func
(
m
*
AlertClassSvc
)
GetDataById
(
req
request
.
DetailAlertClass
)
(
resp
response
.
AlertClassItem
,
err
error
)
{
func
(
a
*
AlertClassSvc
)
GetDataById
(
req
request
.
DetailAlertClass
)
(
resp
response
.
AlertClassItem
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -132,7 +132,7 @@ func (m *AlertClassSvc) GetDataById(req request.DetailAlertClass) (resp response
...
@@ -132,7 +132,7 @@ func (m *AlertClassSvc) GetDataById(req request.DetailAlertClass) (resp response
return
return
}
}
func
(
m
*
AlertClassSvc
)
List
(
req
request
.
ListAlertClass
)
(
resp
response
.
AlertClassList
,
err
error
)
{
func
(
a
*
AlertClassSvc
)
List
(
req
request
.
ListAlertClass
)
(
resp
response
.
AlertClassList
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -151,7 +151,7 @@ func (m *AlertClassSvc) List(req request.ListAlertClass) (resp response.AlertCla
...
@@ -151,7 +151,7 @@ func (m *AlertClassSvc) List(req request.ListAlertClass) (resp response.AlertCla
return
return
}
}
func
(
m
*
AlertClassSvc
)
Tree
(
req
request
.
ListAlertClass
)
(
resp
[]
*
response
.
AlertClassNode
,
err
error
)
{
func
(
a
*
AlertClassSvc
)
Tree
(
req
request
.
ListAlertClass
)
(
resp
[]
*
response
.
AlertClassNode
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -204,7 +204,7 @@ func sortTree(nodes []*response.AlertClassNode) {
...
@@ -204,7 +204,7 @@ func sortTree(nodes []*response.AlertClassNode) {
}
}
}
}
func
(
m
*
AlertClassSvc
)
SortOrderMax
(
parentId
int
)
(
max
int
,
err
error
)
{
func
(
a
*
AlertClassSvc
)
SortOrderMax
(
parentId
int
)
(
max
int
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -215,7 +215,7 @@ func (m *AlertClassSvc) SortOrderMax(parentId int) (max int, err error) {
...
@@ -215,7 +215,7 @@ func (m *AlertClassSvc) SortOrderMax(parentId int) (max int, err error) {
return
return
}
}
func
(
m
*
AlertClassSvc
)
Delete
(
ids
[]
int
)
(
err
error
)
{
func
(
a
*
AlertClassSvc
)
Delete
(
ids
[]
int
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
...
src/service/alert_rules.go
View file @
6a02848b
...
@@ -18,7 +18,7 @@ type AlertRulesSvc struct {
...
@@ -18,7 +18,7 @@ type AlertRulesSvc struct {
User
entity
.
SystemUserInfo
User
entity
.
SystemUserInfo
}
}
func
(
m
*
AlertRulesSvc
)
Add
(
req
request
.
AddAlertRules
)
error
{
func
(
a
*
AlertRulesSvc
)
Add
(
req
request
.
AddAlertRules
)
error
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
err
=
resp
.
DbConnectError
.
WithError
(
err
)
...
@@ -27,9 +27,9 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
...
@@ -27,9 +27,9 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertRules
{
data
:=
entity
.
AlertRules
{
Id
:
uuid
.
New
()
.
String
(),
Id
:
uuid
.
New
()
.
String
(),
CreatedBy
:
m
.
User
.
SystemAccount
,
CreatedBy
:
a
.
User
.
SystemAccount
,
CreatedAt
:
now
,
CreatedAt
:
now
,
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
...
@@ -53,7 +53,7 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
...
@@ -53,7 +53,7 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
metricConfigId
string
metricConfigId
string
)
)
alertClassSvc
:=
AlertClassSvc
{
User
:
m
.
User
}
alertClassSvc
:=
AlertClassSvc
{
User
:
a
.
User
}
classParentId
,
err
=
alertClassSvc
.
Add
(
session
,
request
.
AddAlertClass
{
classParentId
,
err
=
alertClassSvc
.
Add
(
session
,
request
.
AddAlertClass
{
ClassName
:
req
.
ClassParentName
,
ClassName
:
req
.
ClassParentName
,
SortOrder
:
-
1
,
SortOrder
:
-
1
,
...
@@ -74,7 +74,7 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
...
@@ -74,7 +74,7 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
data
.
ClassId
=
classId
data
.
ClassId
=
classId
// 添加指标配置
// 添加指标配置
metricConfigSvc
:=
MetricConfigSvc
{
User
:
m
.
User
}
metricConfigSvc
:=
MetricConfigSvc
{
User
:
a
.
User
}
_
=
copier
.
Copy
(
&
addMetricConfig
,
&
req
)
_
=
copier
.
Copy
(
&
addMetricConfig
,
&
req
)
addMetricConfig
.
SourceFrom
=
2
addMetricConfig
.
SourceFrom
=
2
addMetricConfig
.
MetricName
=
req
.
MetricConfigName
addMetricConfig
.
MetricName
=
req
.
MetricConfigName
...
@@ -97,7 +97,7 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
...
@@ -97,7 +97,7 @@ func (m *AlertRulesSvc) Add(req request.AddAlertRules) error {
return
nil
return
nil
}
}
func
(
m
*
AlertRulesSvc
)
Update
(
req
request
.
UpdateAlertRules
)
error
{
func
(
a
*
AlertRulesSvc
)
Update
(
req
request
.
UpdateAlertRules
)
error
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
err
=
resp
.
DbConnectError
.
WithError
(
err
)
err
=
resp
.
DbConnectError
.
WithError
(
err
)
...
@@ -105,7 +105,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
...
@@ -105,7 +105,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
}
}
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
data
:=
entity
.
AlertRules
{
data
:=
entity
.
AlertRules
{
UpdatedBy
:
m
.
User
.
SystemAccount
,
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
}
}
_
=
copier
.
Copy
(
&
data
,
&
req
)
_
=
copier
.
Copy
(
&
data
,
&
req
)
...
@@ -134,7 +134,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
...
@@ -134,7 +134,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
alertClassItem
response
.
AlertClassItem
alertClassItem
response
.
AlertClassItem
)
)
alertClassSvc
:=
AlertClassSvc
{
User
:
m
.
User
}
alertClassSvc
:=
AlertClassSvc
{
User
:
a
.
User
}
alertClassItem
,
err
=
alertClassSvc
.
GetDataById
(
request
.
DetailAlertClass
{
ClassId
:
dbAlertRules
.
ClassId
})
alertClassItem
,
err
=
alertClassSvc
.
GetDataById
(
request
.
DetailAlertClass
{
ClassId
:
dbAlertRules
.
ClassId
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -155,7 +155,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
...
@@ -155,7 +155,7 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
}
}
// 更新指标配置
// 更新指标配置
metricConfigSvc
:=
MetricConfigSvc
{
User
:
m
.
User
}
metricConfigSvc
:=
MetricConfigSvc
{
User
:
a
.
User
}
_
=
copier
.
Copy
(
&
updateMetricConfig
,
&
req
)
_
=
copier
.
Copy
(
&
updateMetricConfig
,
&
req
)
updateMetricConfig
.
SourceFrom
=
2
updateMetricConfig
.
SourceFrom
=
2
updateMetricConfig
.
Id
=
dbAlertRules
.
MetricConfigId
updateMetricConfig
.
Id
=
dbAlertRules
.
MetricConfigId
...
@@ -175,23 +175,25 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
...
@@ -175,23 +175,25 @@ func (m *AlertRulesSvc) Update(req request.UpdateAlertRules) error {
return
nil
return
nil
}
}
func
(
m
*
AlertRulesSvc
)
GetDataById
(
req
request
.
DetailAlertRules
)
(
resp
response
.
AlertRulesItem
,
err
error
)
{
func
(
a
*
AlertRulesSvc
)
GetDataById
(
req
request
.
DetailAlertRules
)
(
resp
response
.
AlertRulesItem
,
err
error
)
{
db
,
err
:=
client
.
GetDbClient
(
)
list
,
err
:=
a
.
List
(
request
.
ListAlertRules
{
Id
:
req
.
Id
}
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
_
,
err
=
db
.
NewSession
()
.
Table
(
resp
.
TableName
())
.
Where
(
"id = ?"
,
req
.
Id
)
.
Get
(
&
resp
)
if
len
(
list
.
List
)
>=
1
{
resp
=
list
.
List
[
0
]
}
return
return
}
}
func
(
m
*
AlertRulesSvc
)
List
(
req
request
.
ListAlertRules
)
(
resp
response
.
AlertRulesList
,
err
error
)
{
func
(
a
*
AlertRulesSvc
)
List
(
req
request
.
ListAlertRules
)
(
resp
response
.
AlertRulesList
,
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
.
Table
(
new
(
entity
.
AlertRules
))
.
Alias
(
"r"
)
.
Select
(
"r.*
,acp.class_name class_parent_name,ac.class_name,mc.metric_name metric_config_name
"
)
session
.
Join
(
"LEFT"
,
"metric_config mc"
,
"mc.id = r.metric_config_id"
)
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 ac"
,
"ac.class_id = r.class_id"
)
session
.
Join
(
"LEFT"
,
"alert_class acp"
,
"acp.class_id = ac.parent_id"
)
session
.
Join
(
"LEFT"
,
"alert_class acp"
,
"acp.class_id = ac.parent_id"
)
...
@@ -204,6 +206,12 @@ func (m *AlertRulesSvc) List(req request.ListAlertRules) (resp response.AlertRul
...
@@ -204,6 +206,12 @@ func (m *AlertRulesSvc) List(req request.ListAlertRules) (resp response.AlertRul
if
req
.
IsEnabled
>
0
{
if
req
.
IsEnabled
>
0
{
session
.
Where
(
"r.is_enabled = ?"
,
req
.
IsEnabled
)
session
.
Where
(
"r.is_enabled = ?"
,
req
.
IsEnabled
)
}
}
if
req
.
StartTime
!=
""
{
session
.
Where
(
"r.created_at >= ?"
,
req
.
StartTime
)
}
if
req
.
EndTime
!=
""
{
session
.
Where
(
"r.created_at <= ?"
,
req
.
EndTime
)
}
if
req
.
Keyword
!=
""
{
if
req
.
Keyword
!=
""
{
// 预警对象/预警分类/预警指标
// 预警对象/预警分类/预警指标
session
.
Where
(
"r.metric_name LIKE ?"
,
"%"
+
req
.
Keyword
+
"%"
)
.
session
.
Where
(
"r.metric_name LIKE ?"
,
"%"
+
req
.
Keyword
+
"%"
)
.
...
@@ -221,7 +229,7 @@ func (m *AlertRulesSvc) List(req request.ListAlertRules) (resp response.AlertRul
...
@@ -221,7 +229,7 @@ func (m *AlertRulesSvc) List(req request.ListAlertRules) (resp response.AlertRul
return
return
}
}
func
(
m
*
AlertRulesSvc
)
Delete
(
ids
[]
string
)
(
err
error
)
{
func
(
a
*
AlertRulesSvc
)
Delete
(
ids
[]
string
)
(
err
error
)
{
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
...
src/service/prometheus.go
View file @
6a02848b
...
@@ -17,7 +17,7 @@ type PrometheusSvc struct {
...
@@ -17,7 +17,7 @@ type PrometheusSvc struct {
User
entity
.
SystemUserInfo
User
entity
.
SystemUserInfo
}
}
func
(
m
*
PrometheusSvc
)
Label
(
req
request
.
PrometheusLabel
)
(
resp
response
.
PrometheusList
,
err
error
)
{
func
(
p
*
PrometheusSvc
)
Label
(
req
request
.
PrometheusLabel
)
(
resp
response
.
PrometheusList
,
err
error
)
{
var
(
var
(
prometheusLabel
response
.
PrometheusLabel
prometheusLabel
response
.
PrometheusLabel
prometheusSeries
response
.
PrometheusSeries
prometheusSeries
response
.
PrometheusSeries
...
...
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