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
2ac6e23f
Commit
2ac6e23f
authored
Sep 18, 2017
by
bergquist
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'invalid_panel_data'
parents
a687a660
89eda76f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
1 deletions
+83
-1
pkg/services/alerting/extractor.go
+6
-1
pkg/services/alerting/extractor_test.go
+77
-0
No files found.
pkg/services/alerting/extractor.go
View file @
2ac6e23f
...
...
@@ -89,6 +89,11 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
continue
}
panelId
,
err
:=
panel
.
Get
(
"id"
)
.
Int64
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"panel id is required. err %v"
,
err
)
}
// backward compatibility check, can be removed later
enabled
,
hasEnabled
:=
jsonAlert
.
CheckGet
(
"enabled"
)
if
hasEnabled
&&
enabled
.
MustBool
()
==
false
{
...
...
@@ -103,7 +108,7 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
alert
:=
&
m
.
Alert
{
DashboardId
:
e
.
Dash
.
Id
,
OrgId
:
e
.
OrgId
,
PanelId
:
panel
.
Get
(
"id"
)
.
MustInt64
()
,
PanelId
:
panel
Id
,
Id
:
jsonAlert
.
Get
(
"id"
)
.
MustInt64
(),
Name
:
jsonAlert
.
Get
(
"name"
)
.
MustString
(),
Handler
:
jsonAlert
.
Get
(
"handler"
)
.
MustInt64
(),
...
...
pkg/services/alerting/extractor_test.go
View file @
2ac6e23f
...
...
@@ -200,6 +200,83 @@ func TestAlertRuleExtraction(t *testing.T) {
})
})
Convey
(
"Panels missing id should return error"
,
func
()
{
panelWithoutId
:=
`
{
"id": 57,
"title": "Graphite 4",
"originalTitle": "Graphite 4",
"tags": ["graphite"],
"rows": [
{
"panels": [
{
"title": "Active desktop users",
"editable": true,
"type": "graph",
"targets": [
{
"refId": "A",
"target": "aliasByNode(statsd.fakesite.counters.session_start.desktop.count, 4)"
}
],
"datasource": null,
"alert": {
"name": "name1",
"message": "desc1",
"handler": 1,
"frequency": "60s",
"conditions": [
{
"type": "query",
"query": {"params": ["A", "5m", "now"]},
"reducer": {"type": "avg", "params": []},
"evaluator": {"type": ">", "params": [100]}
}
]
}
},
{
"title": "Active mobile users",
"id": 4,
"targets": [
{"refId": "A", "target": ""},
{"refId": "B", "target": "aliasByNode(statsd.fakesite.counters.session_start.mobile.count, 4)"}
],
"datasource": "graphite2",
"alert": {
"name": "name2",
"message": "desc2",
"handler": 0,
"frequency": "60s",
"severity": "warning",
"conditions": [
{
"type": "query",
"query": {"params": ["B", "5m", "now"]},
"reducer": {"type": "avg", "params": []},
"evaluator": {"type": ">", "params": [100]}
}
]
}
}
]
}
]
}`
dashJson
,
err
:=
simplejson
.
NewJson
([]
byte
(
panelWithoutId
))
So
(
err
,
ShouldBeNil
)
dash
:=
m
.
NewDashboardFromJson
(
dashJson
)
extractor
:=
NewDashAlertExtractor
(
dash
,
1
)
_
,
err
=
extractor
.
GetAlerts
()
Convey
(
"panels without Id should return error"
,
func
()
{
So
(
err
,
ShouldNotBeNil
)
})
})
Convey
(
"Parse and validate dashboard containing influxdb alert"
,
func
()
{
json2
:=
`{
...
...
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