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
650a87dc
Commit
650a87dc
authored
Aug 30, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): add alert history api endpoint
ref #5850
parent
1f1d232e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
1 deletions
+91
-1
pkg/api/alerting.go
+32
-0
pkg/api/api.go
+2
-1
pkg/api/dtos/alerting.go
+11
-0
pkg/services/annotations/annotations.go
+9
-0
pkg/services/sqlstore/annotation.go
+37
-0
No files found.
pkg/api/alerting.go
View file @
650a87dc
...
...
@@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/annotations"
)
func
ValidateOrgAlert
(
c
*
middleware
.
Context
)
{
...
...
@@ -212,3 +213,34 @@ func DeleteAlertNotification(c *middleware.Context) Response {
return
ApiSuccess
(
"Notification deleted"
)
}
func
GetAlertHistory
(
c
*
middleware
.
Context
)
Response
{
query
:=
&
annotations
.
ItemQuery
{
AlertId
:
c
.
ParamsInt64
(
"alertId"
),
Type
:
annotations
.
AlertType
,
OrgId
:
c
.
OrgId
,
Limit
:
c
.
QueryInt64
(
"limit"
),
}
repo
:=
annotations
.
GetRepository
()
items
,
err
:=
repo
.
Find
(
query
)
if
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get history for alert"
,
err
)
}
var
result
[]
dtos
.
AlertHistory
for
_
,
item
:=
range
items
{
result
=
append
(
result
,
dtos
.
AlertHistory
{
AlertId
:
item
.
AlertId
,
Timestamp
:
item
.
Timestamp
,
Data
:
item
.
Data
,
NewState
:
item
.
NewState
,
Text
:
item
.
Text
,
Metric
:
item
.
Metric
,
Title
:
item
.
Title
,
})
}
return
Json
(
200
,
result
)
}
pkg/api/api.go
View file @
650a87dc
...
...
@@ -250,11 +250,12 @@ func Register(r *macaron.Macaron) {
r
.
Group
(
"/alerts"
,
func
()
{
r
.
Post
(
"/test"
,
bind
(
dtos
.
AlertTestCommand
{}),
wrap
(
AlertTest
))
//r.Get("/:alertId/states", wrap(GetAlertStates))
r
.
Get
(
"/:alertId"
,
ValidateOrgAlert
,
wrap
(
GetAlert
))
r
.
Get
(
"/"
,
wrap
(
GetAlerts
))
})
r
.
Get
(
"/alert-history/:alertId"
,
ValidateOrgAlert
,
wrap
(
GetAlertHistory
))
r
.
Get
(
"/alert-notifications"
,
wrap
(
GetAlertNotifications
))
r
.
Group
(
"/alert-notifications"
,
func
()
{
...
...
pkg/api/dtos/alerting.go
View file @
650a87dc
...
...
@@ -52,3 +52,14 @@ type EvalMatch struct {
Metric
string
`json:"metric"`
Value
float64
`json:"value"`
}
type
AlertHistory
struct
{
AlertId
int64
`json:"alertId"`
NewState
string
`json:"netState"`
Timestamp
time
.
Time
`json:"timestamp"`
Title
string
`json:"title"`
Text
string
`json:"text"`
Metric
string
`json:"metric"`
Data
*
simplejson
.
Json
`json:"data"`
}
pkg/services/annotations/annotations.go
View file @
650a87dc
...
...
@@ -8,6 +8,15 @@ import (
type
Repository
interface
{
Save
(
item
*
Item
)
error
Find
(
query
*
ItemQuery
)
([]
*
Item
,
error
)
}
type
ItemQuery
struct
{
OrgId
int64
`json:"orgId"`
Type
ItemType
`json:"type"`
AlertId
int64
`json:"alertId"`
Limit
int64
`json:"alertId"`
}
var
repositoryInstance
Repository
...
...
pkg/services/sqlstore/annotation.go
View file @
650a87dc
package
sqlstore
import
(
"bytes"
"fmt"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/services/annotations"
)
...
...
@@ -17,5 +20,39 @@ func (r *SqlAnnotationRepo) Save(item *annotations.Item) error {
return
nil
})
}
func
(
r
*
SqlAnnotationRepo
)
Find
(
query
*
annotations
.
ItemQuery
)
([]
*
annotations
.
Item
,
error
)
{
var
sql
bytes
.
Buffer
params
:=
make
([]
interface
{},
0
)
sql
.
WriteString
(
`SELECT *
from annotation
`
)
sql
.
WriteString
(
`WHERE org_id = ?`
)
params
=
append
(
params
,
query
.
OrgId
)
if
query
.
AlertId
!=
0
{
sql
.
WriteString
(
` AND alert_id = ?`
)
params
=
append
(
params
,
query
.
AlertId
)
}
if
query
.
Type
!=
""
{
sql
.
WriteString
(
` AND type = ?`
)
params
=
append
(
params
,
string
(
query
.
Type
))
}
if
query
.
Limit
==
0
{
query
.
Limit
=
10
}
sql
.
WriteString
(
fmt
.
Sprintf
(
"ORDER BY timestamp DESC LIMIT %v"
,
query
.
Limit
))
items
:=
make
([]
*
annotations
.
Item
,
0
)
if
err
:=
x
.
Sql
(
sql
.
String
(),
params
...
)
.
Find
(
&
items
);
err
!=
nil
{
return
nil
,
err
}
return
items
,
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