Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
1f8f3ed0
Commit
1f8f3ed0
authored
Dec 16, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(api): extracts filter logic for mass pause
parent
fb6aa0e0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
34 deletions
+43
-34
pkg/api/alerting.go
+43
-34
No files found.
pkg/api/alerting.go
View file @
1f8f3ed0
...
@@ -286,51 +286,21 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
...
@@ -286,51 +286,21 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
return
Json
(
200
,
result
)
return
Json
(
200
,
result
)
}
}
func
existInSlice
(
slice
[]
int64
,
value
int64
)
bool
{
for
_
,
v
:=
range
slice
{
if
v
==
value
{
return
true
}
}
return
false
}
//POST /api/alerts/pause
//POST /api/alerts/pause
func
PauseAlerts
(
c
*
middleware
.
Context
,
dto
dtos
.
PauseAlertsCommand
)
Response
{
func
PauseAlerts
(
c
*
middleware
.
Context
,
dto
dtos
.
PauseAlertsCommand
)
Response
{
cmd
:=
&
models
.
GetAllAlertsQuery
{}
alertIdsToUpdate
,
err
:=
getAlertIdsToUpdate
(
dto
)
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
""
,
err
)
}
var
alertsToUpdate
[]
int64
skipFilter
:=
len
(
dto
.
DataSourceIds
)
==
0
for
_
,
alert
:=
range
cmd
.
Result
{
if
skipFilter
{
alertsToUpdate
=
append
(
alertsToUpdate
,
alert
.
Id
)
continue
}
alert
,
err
:=
alerting
.
NewRuleFromDBAlert
(
alert
)
if
err
!=
nil
{
if
err
!=
nil
{
return
ApiError
(
500
,
""
,
err
)
return
ApiError
(
500
,
"Failed to pause alerts"
,
err
)
}
for
_
,
v
:=
range
alert
.
Conditions
{
id
,
exist
:=
v
.
GetDatsourceId
()
if
exist
&&
existInSlice
(
dto
.
DataSourceIds
,
*
id
)
{
alertsToUpdate
=
append
(
alertsToUpdate
,
alert
.
Id
)
}
}
}
}
updateCmd
:=
models
.
PauseAlertCommand
{
updateCmd
:=
models
.
PauseAlertCommand
{
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
AlertIds
:
alertsToUpdate
,
AlertIds
:
alert
Id
sToUpdate
,
Paused
:
dto
.
Paused
,
Paused
:
dto
.
Paused
,
}
}
if
err
:=
bus
.
Dispatch
(
&
updateCmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
updateCmd
);
err
!=
nil
{
return
ApiError
(
500
,
""
,
err
)
return
ApiError
(
500
,
"
Failed to pause alerts
"
,
err
)
}
}
var
response
models
.
AlertStateType
=
models
.
AlertStatePending
var
response
models
.
AlertStateType
=
models
.
AlertStatePending
...
@@ -348,3 +318,42 @@ func PauseAlerts(c *middleware.Context, dto dtos.PauseAlertsCommand) Response {
...
@@ -348,3 +318,42 @@ func PauseAlerts(c *middleware.Context, dto dtos.PauseAlertsCommand) Response {
return
Json
(
200
,
result
)
return
Json
(
200
,
result
)
}
}
func
getAlertIdsToUpdate
(
pauseAlertCmd
dtos
.
PauseAlertsCommand
)
([]
int64
,
error
)
{
cmd
:=
&
models
.
GetAllAlertsQuery
{}
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
return
nil
,
err
}
var
alertIdsToUpdate
[]
int64
updateAllAlerts
:=
len
(
pauseAlertCmd
.
DataSourceIds
)
==
0
for
_
,
alert
:=
range
cmd
.
Result
{
if
updateAllAlerts
{
alertIdsToUpdate
=
append
(
alertIdsToUpdate
,
alert
.
Id
)
continue
}
alert
,
err
:=
alerting
.
NewRuleFromDBAlert
(
alert
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
condition
:=
range
alert
.
Conditions
{
id
,
exist
:=
condition
.
GetDatsourceId
()
if
exist
&&
existInSlice
(
pauseAlertCmd
.
DataSourceIds
,
*
id
)
{
alertIdsToUpdate
=
append
(
alertIdsToUpdate
,
alert
.
Id
)
}
}
}
return
alertIdsToUpdate
,
nil
}
func
existInSlice
(
slice
[]
int64
,
value
int64
)
bool
{
for
_
,
v
:=
range
slice
{
if
v
==
value
{
return
true
}
}
return
false
}
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