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
79fe0195
Commit
79fe0195
authored
Jan 31, 2018
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alerting: small refactoring
parent
eb765d28
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
pkg/api/alerting.go
+17
-8
No files found.
pkg/api/alerting.go
View file @
79fe0195
...
...
@@ -63,9 +63,22 @@ func GetAlerts(c *middleware.Context) Response {
return
ApiError
(
500
,
"List alerts failed"
,
err
)
}
alertDTOs
,
resp
:=
transformToDTOs
(
query
.
Result
,
c
)
if
resp
!=
nil
{
return
resp
}
return
Json
(
200
,
alertDTOs
)
}
func
transformToDTOs
(
alerts
[]
*
models
.
Alert
,
c
*
middleware
.
Context
)
([]
*
dtos
.
AlertRule
,
Response
)
{
if
len
(
alerts
)
==
0
{
return
[]
*
dtos
.
AlertRule
{},
nil
}
dashboardIds
:=
make
([]
int64
,
0
)
alertDTOs
:=
make
([]
*
dtos
.
AlertRule
,
0
)
for
_
,
alert
:=
range
query
.
Result
{
for
_
,
alert
:=
range
alerts
{
dashboardIds
=
append
(
dashboardIds
,
alert
.
DashboardId
)
alertDTOs
=
append
(
alertDTOs
,
&
dtos
.
AlertRule
{
Id
:
alert
.
Id
,
...
...
@@ -84,10 +97,8 @@ func GetAlerts(c *middleware.Context) Response {
DashboardIds
:
dashboardIds
,
}
if
len
(
alertDTOs
)
>
0
{
if
err
:=
bus
.
Dispatch
(
&
dashboardsQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"List alerts failed"
,
err
)
}
return
nil
,
ApiError
(
500
,
"List alerts failed"
,
err
)
}
//TODO: should be possible to speed this up with lookup table
...
...
@@ -106,10 +117,8 @@ func GetAlerts(c *middleware.Context) Response {
OrgRole
:
c
.
SignedInUser
.
OrgRole
,
}
if
len
(
alertDTOs
)
>
0
{
if
err
:=
bus
.
Dispatch
(
&
permissionsQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"List alerts failed"
,
err
)
}
return
nil
,
ApiError
(
500
,
"List alerts failed"
,
err
)
}
for
_
,
alert
:=
range
alertDTOs
{
...
...
@@ -120,7 +129,7 @@ func GetAlerts(c *middleware.Context) Response {
}
}
return
Json
(
200
,
alertDTOs
)
return
alertDTOs
,
nil
}
// POST /api/alerts/test
...
...
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