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
6121d15b
Commit
6121d15b
authored
Jun 23, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): more aggressive requirements for parsing alertrules
parent
8b05af2f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
9 deletions
+19
-9
pkg/services/alerting/alert_rule.go
+15
-2
pkg/services/alerting/alert_rule_test.go
+1
-1
pkg/services/alerting/engine.go
+0
-2
pkg/services/alerting/extractor_test.go
+3
-3
pkg/services/alerting/models.go
+0
-1
No files found.
pkg/services/alerting/alert_rule.go
View file @
6121d15b
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"regexp"
"regexp"
"strconv"
"strconv"
"strings"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/services/alerting/transformers"
"github.com/grafana/grafana/pkg/services/alerting/transformers"
...
@@ -63,7 +64,16 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
...
@@ -63,7 +64,16 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
model
.
State
=
ruleDef
.
State
model
.
State
=
ruleDef
.
State
model
.
Frequency
=
ruleDef
.
Frequency
model
.
Frequency
=
ruleDef
.
Frequency
model
.
NotificationGroups
=
[]
int64
{
1
,
2
}
ngs
:=
ruleDef
.
Settings
.
Get
(
"notificationGroups"
)
.
MustString
()
var
ids
[]
int64
for
_
,
v
:=
range
strings
.
Split
(
ngs
,
","
)
{
id
,
err
:=
strconv
.
Atoi
(
v
)
if
err
==
nil
{
ids
=
append
(
ids
,
int64
(
id
))
}
}
model
.
NotificationGroups
=
ids
critical
:=
ruleDef
.
Settings
.
Get
(
"crit"
)
critical
:=
ruleDef
.
Settings
.
Get
(
"crit"
)
model
.
Critical
=
Level
{
model
.
Critical
=
Level
{
...
@@ -78,6 +88,10 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
...
@@ -78,6 +88,10 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
}
}
model
.
Transform
=
ruleDef
.
Settings
.
Get
(
"transform"
)
.
Get
(
"type"
)
.
MustString
()
model
.
Transform
=
ruleDef
.
Settings
.
Get
(
"transform"
)
.
Get
(
"type"
)
.
MustString
()
if
model
.
Transform
==
""
{
return
nil
,
fmt
.
Errorf
(
"missing transform"
)
}
model
.
TransformParams
=
*
ruleDef
.
Settings
.
Get
(
"transform"
)
model
.
TransformParams
=
*
ruleDef
.
Settings
.
Get
(
"transform"
)
if
model
.
Transform
==
"aggregation"
{
if
model
.
Transform
==
"aggregation"
{
...
@@ -91,7 +105,6 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
...
@@ -91,7 +105,6 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
DatasourceId
:
query
.
Get
(
"datasourceId"
)
.
MustInt64
(),
DatasourceId
:
query
.
Get
(
"datasourceId"
)
.
MustInt64
(),
From
:
query
.
Get
(
"from"
)
.
MustString
(),
From
:
query
.
Get
(
"from"
)
.
MustString
(),
To
:
query
.
Get
(
"to"
)
.
MustString
(),
To
:
query
.
Get
(
"to"
)
.
MustString
(),
Aggregator
:
query
.
Get
(
"agg"
)
.
MustString
(),
}
}
if
model
.
Query
.
Query
==
""
{
if
model
.
Query
.
Query
==
""
{
...
...
pkg/services/alerting/alert_rule_test.go
View file @
6121d15b
...
@@ -55,7 +55,7 @@ func TestAlertRuleModel(t *testing.T) {
...
@@ -55,7 +55,7 @@ func TestAlertRuleModel(t *testing.T) {
"datasourceId": 1
"datasourceId": 1
},
},
"transform": {
"transform": {
"
method
": "avg",
"
type
": "avg",
"name": "aggregation"
"name": "aggregation"
}
}
}
}
...
...
pkg/services/alerting/engine.go
View file @
6121d15b
...
@@ -132,12 +132,10 @@ func (e *Engine) resultHandler() {
...
@@ -132,12 +132,10 @@ func (e *Engine) resultHandler() {
result
.
State
=
alertstates
.
Critical
result
.
State
=
alertstates
.
Critical
result
.
Description
=
fmt
.
Sprintf
(
"Failed to run check after %d retires, Error: %v"
,
maxAlertExecutionRetries
,
result
.
Error
)
result
.
Description
=
fmt
.
Sprintf
(
"Failed to run check after %d retires, Error: %v"
,
maxAlertExecutionRetries
,
result
.
Error
)
//e.reactToState(result)
e
.
responseHandler
.
Handle
(
result
)
e
.
responseHandler
.
Handle
(
result
)
}
}
}
else
{
}
else
{
result
.
AlertJob
.
ResetRetry
()
result
.
AlertJob
.
ResetRetry
()
//e.reactToState(result)
e
.
responseHandler
.
Handle
(
result
)
e
.
responseHandler
.
Handle
(
result
)
}
}
}
}
...
...
pkg/services/alerting/extractor_test.go
View file @
6121d15b
...
@@ -52,8 +52,8 @@ func TestAlertRuleExtraction(t *testing.T) {
...
@@ -52,8 +52,8 @@ func TestAlertRuleExtraction(t *testing.T) {
"to": "now"
"to": "now"
},
},
"transform": {
"transform": {
"
method
": "avg",
"
type
": "avg",
"
typ
e": "aggregation"
"
nam
e": "aggregation"
},
},
"warn": {
"warn": {
"value": 10,
"value": 10,
...
@@ -87,7 +87,7 @@ func TestAlertRuleExtraction(t *testing.T) {
...
@@ -87,7 +87,7 @@ func TestAlertRuleExtraction(t *testing.T) {
"to": "now"
"to": "now"
},
},
"transform": {
"transform": {
"
method
": "avg",
"
type
": "avg",
"name": "aggregation"
"name": "aggregation"
},
},
"warn": {
"warn": {
...
...
pkg/services/alerting/models.go
View file @
6121d15b
...
@@ -47,7 +47,6 @@ type Level struct {
...
@@ -47,7 +47,6 @@ type Level struct {
type
AlertQuery
struct
{
type
AlertQuery
struct
{
Query
string
Query
string
DatasourceId
int64
DatasourceId
int64
Aggregator
string
From
string
From
string
To
string
To
string
}
}
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