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
b9d709ab
Commit
b9d709ab
authored
Nov 15, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): improve error logging for extracting alerts
ref #6576
parent
6e94ccea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
pkg/services/alerting/rule.go
+25
-4
No files found.
pkg/services/alerting/rule.go
View file @
b9d709ab
...
...
@@ -27,10 +27,31 @@ type Rule struct {
type
ValidationError
struct
{
Reason
string
Err
error
Alertid
int64
DashboardId
int64
PanelId
int64
}
func
(
e
ValidationError
)
Error
()
string
{
return
e
.
Reason
extraInfo
:=
""
if
e
.
Alertid
!=
0
{
extraInfo
=
fmt
.
Sprintf
(
"%s AlertId: %v"
,
extraInfo
,
e
.
Alertid
)
}
if
e
.
PanelId
!=
0
{
extraInfo
=
fmt
.
Sprintf
(
"%s PanelId: %v "
,
extraInfo
,
e
.
PanelId
)
}
if
e
.
DashboardId
!=
0
{
extraInfo
=
fmt
.
Sprintf
(
"%s DashboardId: %v"
,
extraInfo
,
e
.
DashboardId
)
}
if
e
.
Err
!=
nil
{
return
fmt
.
Sprintf
(
"%s %s%s"
,
e
.
Err
.
Error
(),
e
.
Reason
,
extraInfo
)
}
return
fmt
.
Sprintf
(
"Failed to extract alert.Reason: %s %s"
,
e
.
Reason
,
extraInfo
)
}
var
(
...
...
@@ -83,7 +104,7 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
for
_
,
v
:=
range
ruleDef
.
Settings
.
Get
(
"notifications"
)
.
MustArray
()
{
jsonModel
:=
simplejson
.
NewFromAny
(
v
)
if
id
,
err
:=
jsonModel
.
Get
(
"id"
)
.
Int64
();
err
!=
nil
{
return
nil
,
ValidationError
{
Reason
:
"Invalid notification schema"
}
return
nil
,
ValidationError
{
Reason
:
"Invalid notification schema"
,
DashboardId
:
model
.
DashboardId
,
Alertid
:
model
.
Id
,
PanelId
:
model
.
PanelId
}
}
else
{
model
.
Notifications
=
append
(
model
.
Notifications
,
id
)
}
...
...
@@ -93,10 +114,10 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
conditionModel
:=
simplejson
.
NewFromAny
(
condition
)
conditionType
:=
conditionModel
.
Get
(
"type"
)
.
MustString
()
if
factory
,
exist
:=
conditionFactories
[
conditionType
];
!
exist
{
return
nil
,
ValidationError
{
Reason
:
"Unknown alert condition: "
+
conditionType
}
return
nil
,
ValidationError
{
Reason
:
"Unknown alert condition: "
+
conditionType
,
DashboardId
:
model
.
DashboardId
,
Alertid
:
model
.
Id
,
PanelId
:
model
.
PanelId
}
}
else
{
if
queryCondition
,
err
:=
factory
(
conditionModel
,
index
);
err
!=
nil
{
return
nil
,
err
return
nil
,
ValidationError
{
Err
:
err
,
DashboardId
:
model
.
DashboardId
,
Alertid
:
model
.
Id
,
PanelId
:
model
.
PanelId
}
}
else
{
model
.
Conditions
=
append
(
model
.
Conditions
,
queryCondition
)
}
...
...
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