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
a0a57ac3
Unverified
Commit
a0a57ac3
authored
Mar 14, 2018
by
Carl Bergquist
Committed by
GitHub
Mar 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11236 from grafana/alerting_collapsed_panels
alerting: supports extracting alerts from collapsed panels
parents
9cae6f05
be7ec310
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
638 additions
and
0 deletions
+638
-0
pkg/services/alerting/extractor.go
+15
-0
pkg/services/alerting/extractor_test.go
+26
-0
pkg/services/alerting/test-data/collapsed-panels.json
+597
-0
No files found.
pkg/services/alerting/extractor.go
View file @
a0a57ac3
...
...
@@ -74,6 +74,21 @@ func (e *DashAlertExtractor) GetAlertFromPanels(jsonWithPanels *simplejson.Json)
for
_
,
panelObj
:=
range
jsonWithPanels
.
Get
(
"panels"
)
.
MustArray
()
{
panel
:=
simplejson
.
NewFromAny
(
panelObj
)
collapsedJson
,
collapsed
:=
panel
.
CheckGet
(
"collapsed"
)
// check if the panel is collapsed
if
collapsed
&&
collapsedJson
.
MustBool
()
{
// extract alerts from sub panels for collapsed panels
als
,
err
:=
e
.
GetAlertFromPanels
(
panel
)
if
err
!=
nil
{
return
nil
,
err
}
alerts
=
append
(
alerts
,
als
...
)
continue
}
jsonAlert
,
hasAlert
:=
panel
.
CheckGet
(
"alert"
)
if
!
hasAlert
{
...
...
pkg/services/alerting/extractor_test.go
View file @
a0a57ac3
...
...
@@ -22,6 +22,7 @@ func TestAlertRuleExtraction(t *testing.T) {
defaultDs
:=
&
m
.
DataSource
{
Id
:
12
,
OrgId
:
1
,
Name
:
"I am default"
,
IsDefault
:
true
}
graphite2Ds
:=
&
m
.
DataSource
{
Id
:
15
,
OrgId
:
1
,
Name
:
"graphite2"
}
influxDBDs
:=
&
m
.
DataSource
{
Id
:
16
,
OrgId
:
1
,
Name
:
"InfluxDB"
}
prom
:=
&
m
.
DataSource
{
Id
:
17
,
OrgId
:
1
,
Name
:
"Prometheus"
}
bus
.
AddHandler
(
"test"
,
func
(
query
*
m
.
GetDataSourcesQuery
)
error
{
query
.
Result
=
[]
*
m
.
DataSource
{
defaultDs
,
graphite2Ds
}
...
...
@@ -38,6 +39,10 @@ func TestAlertRuleExtraction(t *testing.T) {
if
query
.
Name
==
influxDBDs
.
Name
{
query
.
Result
=
influxDBDs
}
if
query
.
Name
==
prom
.
Name
{
query
.
Result
=
prom
}
return
nil
})
...
...
@@ -214,5 +219,26 @@ func TestAlertRuleExtraction(t *testing.T) {
}
})
})
Convey
(
"Should be able to extract collapsed panels"
,
func
()
{
json
,
err
:=
ioutil
.
ReadFile
(
"./test-data/collapsed-panels.json"
)
So
(
err
,
ShouldBeNil
)
dashJson
,
err
:=
simplejson
.
NewJson
(
json
)
So
(
err
,
ShouldBeNil
)
dash
:=
m
.
NewDashboardFromJson
(
dashJson
)
extractor
:=
NewDashAlertExtractor
(
dash
,
1
)
alerts
,
err
:=
extractor
.
GetAlerts
()
Convey
(
"Get rules without error"
,
func
()
{
So
(
err
,
ShouldBeNil
)
})
Convey
(
"should be able to extract collapsed alerts"
,
func
()
{
So
(
len
(
alerts
),
ShouldEqual
,
4
)
})
})
})
}
pkg/services/alerting/test-data/collapsed-panels.json
0 → 100644
View file @
a0a57ac3
{
"annotations"
:
{
"list"
:
[
{
"builtIn"
:
1
,
"datasource"
:
"-- Grafana --"
,
"enable"
:
true
,
"hide"
:
true
,
"iconColor"
:
"rgba(0, 211, 255, 1)"
,
"name"
:
"Annotations & Alerts"
,
"type"
:
"dashboard"
}
]
},
"editable"
:
true
,
"gnetId"
:
null
,
"graphTooltip"
:
0
,
"id"
:
127
,
"links"
:
[],
"panels"
:
[
{
"gridPos"
:
{
"h"
:
1
,
"w"
:
24
,
"x"
:
0
,
"y"
:
0
},
"id"
:
9
,
"title"
:
"Row title"
,
"type"
:
"row"
},
{
"alert"
:
{
"conditions"
:
[
{
"evaluator"
:
{
"params"
:
[
200
],
"type"
:
"gt"
},
"operator"
:
{
"type"
:
"and"
},
"query"
:
{
"params"
:
[
"A"
,
"5m"
,
"now"
]
},
"reducer"
:
{
"params"
:
[],
"type"
:
"avg"
},
"type"
:
"query"
}
],
"executionErrorState"
:
"alerting"
,
"frequency"
:
"10s"
,
"handler"
:
1
,
"name"
:
"Panel Title alert"
,
"noDataState"
:
"no_data"
,
"notifications"
:
[]
},
"aliasColors"
:
{},
"bars"
:
false
,
"dashLength"
:
10
,
"dashes"
:
false
,
"datasource"
:
"Prometheus"
,
"fill"
:
1
,
"gridPos"
:
{
"h"
:
9
,
"w"
:
12
,
"x"
:
0
,
"y"
:
1
},
"id"
:
10
,
"legend"
:
{
"avg"
:
false
,
"current"
:
false
,
"max"
:
false
,
"min"
:
false
,
"show"
:
true
,
"total"
:
false
,
"values"
:
false
},
"lines"
:
true
,
"linewidth"
:
1
,
"nullPointMode"
:
"null"
,
"percentage"
:
false
,
"pointradius"
:
5
,
"points"
:
false
,
"renderer"
:
"flot"
,
"seriesOverrides"
:
[],
"spaceLength"
:
10
,
"stack"
:
false
,
"steppedLine"
:
false
,
"targets"
:
[
{
"expr"
:
"go_goroutines"
,
"format"
:
"time_series"
,
"intervalFactor"
:
1
,
"legendFormat"
:
"{{job}}"
,
"refId"
:
"A"
}
],
"thresholds"
:
[
{
"colorMode"
:
"critical"
,
"fill"
:
true
,
"line"
:
true
,
"op"
:
"gt"
,
"value"
:
200
}
],
"timeFrom"
:
null
,
"timeShift"
:
null
,
"title"
:
"Panel Title"
,
"tooltip"
:
{
"shared"
:
true
,
"sort"
:
0
,
"value_type"
:
"individual"
},
"type"
:
"graph"
,
"xaxis"
:
{
"buckets"
:
null
,
"mode"
:
"time"
,
"name"
:
null
,
"show"
:
true
,
"values"
:
[]
},
"yaxes"
:
[
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
},
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
}
]
},
{
"gridPos"
:
{
"h"
:
9
,
"w"
:
12
,
"x"
:
12
,
"y"
:
1
},
"id"
:
14
,
"limit"
:
10
,
"links"
:
[],
"onlyAlertsOnDashboard"
:
true
,
"show"
:
"current"
,
"sortOrder"
:
1
,
"stateFilter"
:
[],
"title"
:
"Panel Title"
,
"type"
:
"alertlist"
},
{
"collapsed"
:
true
,
"gridPos"
:
{
"h"
:
1
,
"w"
:
24
,
"x"
:
0
,
"y"
:
10
},
"id"
:
6
,
"panels"
:
[
{
"alert"
:
{
"conditions"
:
[
{
"evaluator"
:
{
"params"
:
[
200
],
"type"
:
"gt"
},
"operator"
:
{
"type"
:
"and"
},
"query"
:
{
"params"
:
[
"A"
,
"5m"
,
"now"
]
},
"reducer"
:
{
"params"
:
[],
"type"
:
"avg"
},
"type"
:
"query"
}
],
"executionErrorState"
:
"alerting"
,
"frequency"
:
"10s"
,
"handler"
:
1
,
"name"
:
"Panel 2 alert"
,
"noDataState"
:
"no_data"
,
"notifications"
:
[]
},
"aliasColors"
:
{},
"bars"
:
false
,
"dashLength"
:
10
,
"dashes"
:
false
,
"datasource"
:
"Prometheus"
,
"fill"
:
1
,
"gridPos"
:
{
"h"
:
9
,
"w"
:
12
,
"x"
:
0
,
"y"
:
11
},
"id"
:
11
,
"legend"
:
{
"avg"
:
false
,
"current"
:
false
,
"max"
:
false
,
"min"
:
false
,
"show"
:
true
,
"total"
:
false
,
"values"
:
false
},
"lines"
:
true
,
"linewidth"
:
1
,
"links"
:
[],
"nullPointMode"
:
"null"
,
"percentage"
:
false
,
"pointradius"
:
5
,
"points"
:
false
,
"renderer"
:
"flot"
,
"seriesOverrides"
:
[],
"spaceLength"
:
10
,
"stack"
:
false
,
"steppedLine"
:
false
,
"targets"
:
[
{
"expr"
:
"go_goroutines"
,
"format"
:
"time_series"
,
"intervalFactor"
:
1
,
"legendFormat"
:
"{{job}}"
,
"refId"
:
"A"
}
],
"thresholds"
:
[
{
"colorMode"
:
"critical"
,
"fill"
:
true
,
"line"
:
true
,
"op"
:
"gt"
,
"value"
:
200
}
],
"timeFrom"
:
null
,
"timeShift"
:
null
,
"title"
:
"Panel 2"
,
"tooltip"
:
{
"shared"
:
true
,
"sort"
:
0
,
"value_type"
:
"individual"
},
"type"
:
"graph"
,
"xaxis"
:
{
"buckets"
:
null
,
"mode"
:
"time"
,
"name"
:
null
,
"show"
:
true
,
"values"
:
[]
},
"yaxes"
:
[
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
},
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
}
]
},
{
"alert"
:
{
"conditions"
:
[
{
"evaluator"
:
{
"params"
:
[
200
],
"type"
:
"gt"
},
"operator"
:
{
"type"
:
"and"
},
"query"
:
{
"params"
:
[
"A"
,
"5m"
,
"now"
]
},
"reducer"
:
{
"params"
:
[],
"type"
:
"avg"
},
"type"
:
"query"
}
],
"executionErrorState"
:
"alerting"
,
"frequency"
:
"10s"
,
"handler"
:
1
,
"name"
:
"Panel 4 alert"
,
"noDataState"
:
"no_data"
,
"notifications"
:
[]
},
"aliasColors"
:
{},
"bars"
:
false
,
"dashLength"
:
10
,
"dashes"
:
false
,
"datasource"
:
"Prometheus"
,
"fill"
:
1
,
"gridPos"
:
{
"h"
:
9
,
"w"
:
12
,
"x"
:
12
,
"y"
:
11
},
"id"
:
15
,
"legend"
:
{
"avg"
:
false
,
"current"
:
false
,
"max"
:
false
,
"min"
:
false
,
"show"
:
true
,
"total"
:
false
,
"values"
:
false
},
"lines"
:
true
,
"linewidth"
:
1
,
"links"
:
[],
"nullPointMode"
:
"null"
,
"percentage"
:
false
,
"pointradius"
:
5
,
"points"
:
false
,
"renderer"
:
"flot"
,
"seriesOverrides"
:
[],
"spaceLength"
:
10
,
"stack"
:
false
,
"steppedLine"
:
false
,
"targets"
:
[
{
"expr"
:
"go_goroutines"
,
"format"
:
"time_series"
,
"intervalFactor"
:
1
,
"legendFormat"
:
"{{job}}"
,
"refId"
:
"A"
}
],
"thresholds"
:
[
{
"colorMode"
:
"critical"
,
"fill"
:
true
,
"line"
:
true
,
"op"
:
"gt"
,
"value"
:
200
}
],
"timeFrom"
:
null
,
"timeShift"
:
null
,
"title"
:
"Panel 4"
,
"tooltip"
:
{
"shared"
:
true
,
"sort"
:
0
,
"value_type"
:
"individual"
},
"type"
:
"graph"
,
"xaxis"
:
{
"buckets"
:
null
,
"mode"
:
"time"
,
"name"
:
null
,
"show"
:
true
,
"values"
:
[]
},
"yaxes"
:
[
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
},
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
}
]
}
],
"title"
:
"Row title"
,
"type"
:
"row"
},
{
"gridPos"
:
{
"h"
:
1
,
"w"
:
24
,
"x"
:
0
,
"y"
:
11
},
"id"
:
4
,
"title"
:
"Row title"
,
"type"
:
"row"
},
{
"alert"
:
{
"conditions"
:
[
{
"evaluator"
:
{
"params"
:
[
200
],
"type"
:
"gt"
},
"operator"
:
{
"type"
:
"and"
},
"query"
:
{
"params"
:
[
"A"
,
"5m"
,
"now"
]
},
"reducer"
:
{
"params"
:
[],
"type"
:
"avg"
},
"type"
:
"query"
}
],
"executionErrorState"
:
"alerting"
,
"frequency"
:
"10s"
,
"handler"
:
1
,
"name"
:
"Panel 3 alert"
,
"noDataState"
:
"no_data"
,
"notifications"
:
[]
},
"aliasColors"
:
{},
"bars"
:
false
,
"dashLength"
:
10
,
"dashes"
:
false
,
"datasource"
:
"Prometheus"
,
"fill"
:
1
,
"gridPos"
:
{
"h"
:
9
,
"w"
:
12
,
"x"
:
0
,
"y"
:
12
},
"id"
:
12
,
"legend"
:
{
"avg"
:
false
,
"current"
:
false
,
"max"
:
false
,
"min"
:
false
,
"show"
:
true
,
"total"
:
false
,
"values"
:
false
},
"lines"
:
true
,
"linewidth"
:
1
,
"links"
:
[],
"nullPointMode"
:
"null"
,
"percentage"
:
false
,
"pointradius"
:
5
,
"points"
:
false
,
"renderer"
:
"flot"
,
"seriesOverrides"
:
[],
"spaceLength"
:
10
,
"stack"
:
false
,
"steppedLine"
:
false
,
"targets"
:
[
{
"expr"
:
"go_goroutines"
,
"format"
:
"time_series"
,
"intervalFactor"
:
1
,
"legendFormat"
:
"{{job}}"
,
"refId"
:
"A"
}
],
"thresholds"
:
[
{
"colorMode"
:
"critical"
,
"fill"
:
true
,
"line"
:
true
,
"op"
:
"gt"
,
"value"
:
200
}
],
"timeFrom"
:
null
,
"timeShift"
:
null
,
"title"
:
"Panel 3"
,
"tooltip"
:
{
"shared"
:
true
,
"sort"
:
0
,
"value_type"
:
"individual"
},
"type"
:
"graph"
,
"xaxis"
:
{
"buckets"
:
null
,
"mode"
:
"time"
,
"name"
:
null
,
"show"
:
true
,
"values"
:
[]
},
"yaxes"
:
[
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
},
{
"format"
:
"short"
,
"label"
:
null
,
"logBase"
:
1
,
"max"
:
null
,
"min"
:
null
,
"show"
:
true
}
]
}
],
"schemaVersion"
:
16
,
"style"
:
"dark"
,
"tags"
:
[],
"templating"
:
{
"list"
:
[]
},
"time"
:
{
"from"
:
"now-6h"
,
"to"
:
"now"
},
"timepicker"
:
{
"refresh_intervals"
:
[
"5s"
,
"10s"
,
"30s"
,
"1m"
,
"5m"
,
"15m"
,
"30m"
,
"1h"
,
"2h"
,
"1d"
],
"time_options"
:
[
"5m"
,
"15m"
,
"1h"
,
"6h"
,
"12h"
,
"24h"
,
"2d"
,
"7d"
,
"30d"
]
},
"timezone"
:
""
,
"title"
:
"New dashboard Copy"
,
"uid"
:
"6v5pg36zk"
,
"version"
:
17
}
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