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
fecb1d1c
Commit
fecb1d1c
authored
Jul 20, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 完善预警规则设置删除逻辑
parent
e6169241
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
4 deletions
+76
-4
src/bean/vo/request/alert.go
src/bean/vo/request/alert.go
+6
-2
src/service/alert.go
src/service/alert.go
+56
-0
src/service/alert_rules.go
src/service/alert_rules.go
+14
-2
No files found.
src/bean/vo/request/alert.go
View file @
fecb1d1c
...
@@ -19,9 +19,13 @@ type ListAlert struct {
...
@@ -19,9 +19,13 @@ type ListAlert struct {
Pagination
Pagination
}
}
type
ExistAlert
struct
{
Id
int
`json:"id" form:"id"`
AlertRulesId
string
`json:"alert_rules_id" form:"'alert_rules_id'"`
// 告警规则id
}
type
UpdateAlert
struct
{
type
UpdateAlert
struct
{
Id
int
`json:"id" form:"id" binding:"required"`
Id
int
`json:"id" form:"id" binding:"required"`
//Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
CloseRemark
string
`json:"close_remark" form:"close_remark"`
// 关闭备注
CloseRemark
string
`json:"close_remark" form:"close_remark"`
// 关闭备注
DeferPush
int
`json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"`
// 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
DeferPush
int
`json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"`
// 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
...
...
src/service/alert.go
View file @
fecb1d1c
...
@@ -437,6 +437,62 @@ func (a *AlertSvc) IndexSearch(req request.ListAlert) (resp response.AlertList,
...
@@ -437,6 +437,62 @@ func (a *AlertSvc) IndexSearch(req request.ListAlert) (resp response.AlertList,
return
return
}
}
func
(
a
*
AlertSvc
)
IndexDocExist
(
req
request
.
ExistAlert
)
(
exist
bool
,
err
error
)
{
var
(
sources
response
.
OpenSearchSource
)
cli
,
err
:=
client
.
GetOpenSearch
()
if
err
!=
nil
{
return
}
boolQuery
:=
elastic
.
NewBoolQuery
()
if
req
.
Id
!=
0
{
boolQuery
.
Must
(
elastic
.
NewTermQuery
(
"id"
,
req
.
Id
))
}
if
req
.
AlertRulesId
!=
""
{
boolQuery
.
Must
(
elastic
.
NewTermQuery
(
"alert_rules_id"
,
req
.
AlertRulesId
))
}
querySource
,
_
:=
boolQuery
.
Source
()
b
,
_
:=
json
.
Marshal
(
querySource
)
content
:=
strings
.
NewReader
(
fmt
.
Sprintf
(
`{
"query": %s,
"from": %d,
"size": %d}`
,
string
(
b
),
0
,
1
))
res
:=
opensearchapi
.
SearchRequest
{
Index
:
[]
string
{
OpenSearchIndex
},
Body
:
content
,
Sort
:
[]
string
{
"id"
},
}
do
,
err
:=
res
.
Do
(
context
.
Background
(),
cli
)
if
err
!=
nil
{
return
}
defer
do
.
Body
.
Close
()
if
do
.
StatusCode
!=
http
.
StatusOK
{
err
=
errors
.
New
(
do
.
String
())
return
}
body
,
err
:=
io
.
ReadAll
(
do
.
Body
)
if
err
!=
nil
{
return
}
err
=
json
.
Unmarshal
(
body
,
&
sources
)
if
err
!=
nil
{
return
}
if
sources
.
Hits
.
Total
.
Value
==
1
{
exist
=
true
}
return
}
func
(
a
*
AlertSvc
)
IndexUpdate
(
req
request
.
UpdateAlert
)
(
err
error
)
{
func
(
a
*
AlertSvc
)
IndexUpdate
(
req
request
.
UpdateAlert
)
(
err
error
)
{
var
(
var
(
sources
response
.
OpenSearchSource
sources
response
.
OpenSearchSource
...
...
src/service/alert_rules.go
View file @
fecb1d1c
package
service
package
service
import
(
import
(
"errors"
"github.com/google/uuid"
"github.com/google/uuid"
"github.com/jinzhu/copier"
"github.com/jinzhu/copier"
json
"github.com/json-iterator/go"
json
"github.com/json-iterator/go"
...
@@ -260,11 +261,22 @@ func (a *AlertRulesSvc) List(req request.ListAlertRules) (resp response.AlertRul
...
@@ -260,11 +261,22 @@ func (a *AlertRulesSvc) List(req request.ListAlertRules) (resp response.AlertRul
}
}
func
(
a
*
AlertRulesSvc
)
Delete
(
ids
[]
string
)
(
err
error
)
{
func
(
a
*
AlertRulesSvc
)
Delete
(
ids
[]
string
)
(
err
error
)
{
var
exist
bool
db
,
err
:=
client
.
GetDbClient
()
db
,
err
:=
client
.
GetDbClient
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
// TODO 批量删除表中的多出数据
alertSvc
:=
AlertSvc
{
User
:
a
.
User
}
_
,
err
=
db
.
NewSession
()
.
In
(
"id"
,
ids
)
.
Delete
(
new
(
entity
.
AlertRules
))
for
_
,
id
:=
range
ids
{
exist
,
err
=
alertSvc
.
IndexDocExist
(
request
.
ExistAlert
{
AlertRulesId
:
id
})
if
err
!=
nil
{
return
}
if
!
exist
{
_
,
err
=
db
.
NewSession
()
.
Where
(
"id = ?"
,
id
)
.
Delete
(
new
(
entity
.
AlertRules
))
}
else
{
return
errors
.
New
(
"alert_rules_id already exists in opensearch"
)
}
}
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