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
d2205166
Unverified
Commit
d2205166
authored
Mar 07, 2018
by
Carl Bergquist
Committed by
GitHub
Mar 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11145 from grafana/alerting-invalid-data
alerting: fixes validation error when saving alerts in dash
parents
d07aff89
d96fbb48
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
2 deletions
+86
-2
pkg/services/alerting/extractor.go
+7
-2
pkg/services/alerting/extractor_test.go
+16
-0
pkg/services/alerting/test-data/panel-with-id-0.json
+63
-0
No files found.
pkg/services/alerting/extractor.go
View file @
d2205166
...
@@ -143,10 +143,15 @@ func (e *DashAlertExtractor) GetAlertFromPanels(jsonWithPanels *simplejson.Json)
...
@@ -143,10 +143,15 @@ func (e *DashAlertExtractor) GetAlertFromPanels(jsonWithPanels *simplejson.Json)
// validate
// validate
_
,
err
=
NewRuleFromDBAlert
(
alert
)
_
,
err
=
NewRuleFromDBAlert
(
alert
)
if
err
==
nil
&&
alert
.
ValidToSave
()
{
if
err
!=
nil
{
return
nil
,
err
}
if
alert
.
ValidToSave
()
{
alerts
=
append
(
alerts
,
alert
)
alerts
=
append
(
alerts
,
alert
)
}
else
{
}
else
{
return
nil
,
err
e
.
log
.
Debug
(
"Invalid Alert Data. Dashboard, Org or Panel ID is not correct"
,
"alertName"
,
alert
.
Name
,
"panelId"
,
alert
.
PanelId
)
return
nil
,
m
.
ErrDashboardContainsInvalidAlertData
}
}
}
}
...
...
pkg/services/alerting/extractor_test.go
View file @
d2205166
...
@@ -150,6 +150,22 @@ func TestAlertRuleExtraction(t *testing.T) {
...
@@ -150,6 +150,22 @@ func TestAlertRuleExtraction(t *testing.T) {
})
})
})
})
Convey
(
"Panel with id set to zero should return error"
,
func
()
{
panelWithIdZero
,
err
:=
ioutil
.
ReadFile
(
"./test-data/panel-with-id-0.json"
)
So
(
err
,
ShouldBeNil
)
dashJson
,
err
:=
simplejson
.
NewJson
([]
byte
(
panelWithIdZero
))
So
(
err
,
ShouldBeNil
)
dash
:=
m
.
NewDashboardFromJson
(
dashJson
)
extractor
:=
NewDashAlertExtractor
(
dash
,
1
)
_
,
err
=
extractor
.
GetAlerts
()
Convey
(
"panel with id 0 should return error"
,
func
()
{
So
(
err
,
ShouldNotBeNil
)
})
})
Convey
(
"Parse alerts from dashboard without rows"
,
func
()
{
Convey
(
"Parse alerts from dashboard without rows"
,
func
()
{
json
,
err
:=
ioutil
.
ReadFile
(
"./test-data/v5-dashboard.json"
)
json
,
err
:=
ioutil
.
ReadFile
(
"./test-data/v5-dashboard.json"
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
...
...
pkg/services/alerting/test-data/panel-with-id-0.json
0 → 100644
View file @
d2205166
{
"id"
:
57
,
"title"
:
"Graphite 4"
,
"originalTitle"
:
"Graphite 4"
,
"tags"
:
[
"graphite"
],
"rows"
:
[
{
"panels"
:
[
{
"title"
:
"Active desktop users"
,
"id"
:
0
,
"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
]}
}
]
}
}
]
}
]
}
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