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
ccee1b3f
Commit
ccee1b3f
authored
Oct 11, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(alerting): fix bug with unhandled error
closes #6239
parent
0d4b00df
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
9 deletions
+29
-9
pkg/services/alerting/extractor.go
+7
-2
pkg/services/alerting/rule.go
+13
-3
pkg/services/alerting/rule_test.go
+9
-4
No files found.
pkg/services/alerting/extractor.go
View file @
ccee1b3f
...
...
@@ -80,6 +80,11 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
continue
}
frequency
,
err
:=
getTimeDurationStringToSeconds
(
jsonAlert
.
Get
(
"frequency"
)
.
MustString
())
if
err
!=
nil
{
return
nil
,
ValidationError
{
Reason
:
"Could not parse frequency"
}
}
alert
:=
&
m
.
Alert
{
DashboardId
:
e
.
Dash
.
Id
,
OrgId
:
e
.
OrgId
,
...
...
@@ -88,7 +93,7 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
Name
:
jsonAlert
.
Get
(
"name"
)
.
MustString
(),
Handler
:
jsonAlert
.
Get
(
"handler"
)
.
MustInt64
(),
Message
:
jsonAlert
.
Get
(
"message"
)
.
MustString
(),
Frequency
:
getTimeDurationStringToSeconds
(
jsonAlert
.
Get
(
"frequency"
)
.
MustString
())
,
Frequency
:
frequency
,
}
for
_
,
condition
:=
range
jsonAlert
.
Get
(
"conditions"
)
.
MustArray
()
{
...
...
@@ -121,7 +126,7 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
alert
.
Settings
=
jsonAlert
// validate
_
,
err
:
=
NewRuleFromDBAlert
(
alert
)
_
,
err
=
NewRuleFromDBAlert
(
alert
)
if
err
==
nil
&&
alert
.
ValidToSave
()
{
alerts
=
append
(
alerts
,
alert
)
}
else
{
...
...
pkg/services/alerting/rule.go
View file @
ccee1b3f
...
...
@@ -43,17 +43,27 @@ var unitMultiplier = map[string]int{
"h"
:
3600
,
}
func
getTimeDurationStringToSeconds
(
str
string
)
int64
{
func
getTimeDurationStringToSeconds
(
str
string
)
(
int64
,
error
)
{
multiplier
:=
1
value
,
_
:=
strconv
.
Atoi
(
ValueFormatRegex
.
FindAllString
(
str
,
1
)[
0
])
matches
:=
ValueFormatRegex
.
FindAllString
(
str
,
1
)
if
len
(
matches
)
<=
0
{
return
0
,
fmt
.
Errorf
(
"Frequency could not be parsed"
)
}
value
,
err
:=
strconv
.
Atoi
(
matches
[
0
])
if
err
!=
nil
{
return
0
,
err
}
unit
:=
UnitFormatRegex
.
FindAllString
(
str
,
1
)[
0
]
if
val
,
ok
:=
unitMultiplier
[
unit
];
ok
{
multiplier
=
val
}
return
int64
(
value
*
multiplier
)
return
int64
(
value
*
multiplier
)
,
nil
}
func
NewRuleFromDBAlert
(
ruleDef
*
m
.
Alert
)
(
*
Rule
,
error
)
{
...
...
pkg/services/alerting/rule_test.go
View file @
ccee1b3f
...
...
@@ -20,25 +20,30 @@ func TestAlertRuleModel(t *testing.T) {
})
Convey
(
"Can parse seconds"
,
func
()
{
seconds
:=
getTimeDurationStringToSeconds
(
"10s"
)
seconds
,
_
:=
getTimeDurationStringToSeconds
(
"10s"
)
So
(
seconds
,
ShouldEqual
,
10
)
})
Convey
(
"Can parse minutes"
,
func
()
{
seconds
:=
getTimeDurationStringToSeconds
(
"10m"
)
seconds
,
_
:=
getTimeDurationStringToSeconds
(
"10m"
)
So
(
seconds
,
ShouldEqual
,
600
)
})
Convey
(
"Can parse hours"
,
func
()
{
seconds
:=
getTimeDurationStringToSeconds
(
"1h"
)
seconds
,
_
:=
getTimeDurationStringToSeconds
(
"1h"
)
So
(
seconds
,
ShouldEqual
,
3600
)
})
Convey
(
"defaults to seconds"
,
func
()
{
seconds
:=
getTimeDurationStringToSeconds
(
"1o"
)
seconds
,
_
:=
getTimeDurationStringToSeconds
(
"1o"
)
So
(
seconds
,
ShouldEqual
,
1
)
})
Convey
(
"should return err for empty string"
,
func
()
{
_
,
err
:=
getTimeDurationStringToSeconds
(
""
)
So
(
err
,
ShouldNotBeNil
)
})
Convey
(
"can construct alert rule model"
,
func
()
{
json
:=
`
{
...
...
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