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
2b39353a
Commit
2b39353a
authored
Jul 05, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 完善预警规则设置参数
parent
d5d5cf64
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
6 deletions
+50
-6
src/bean/entity/alert_rules.go
src/bean/entity/alert_rules.go
+5
-4
src/bean/vo/request/alert_rules.go
src/bean/vo/request/alert_rules.go
+7
-2
src/controller/alert_rules.go
src/controller/alert_rules.go
+17
-0
src/router/alertrulesrouter.go.go
src/router/alertrulesrouter.go.go
+1
-0
src/service/alert_rules.go
src/service/alert_rules.go
+20
-0
No files found.
src/bean/entity/alert_rules.go
View file @
2b39353a
...
@@ -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"`
}
}
src/bean/vo/request/alert_rules.go
View file @
2b39353a
...
@@ -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:"o
mitempty,oneof=0 1 2"`
// 是否开启 1:是 2:否
IsEnabled
int
`json:"is_enabled" form:"is_enabled" binding:"o
neof=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
{
...
...
src/controller/alert_rules.go
View file @
2b39353a
...
@@ -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
{
...
...
src/router/alertrulesrouter.go.go
View file @
2b39353a
...
@@ -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
)
...
...
src/service/alert_rules.go
View file @
2b39353a
...
@@ -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
{
...
...
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