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
7ddd625e
Commit
7ddd625e
authored
Aug 31, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): add slack/email support for execution errors
parent
4619a05f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
21 deletions
+43
-21
pkg/services/alerting/eval_context.go
+26
-16
pkg/services/alerting/notifier.go
+0
-1
pkg/services/alerting/notifiers/email.go
+1
-1
pkg/services/alerting/notifiers/slack.go
+15
-2
pkg/services/alerting/result_handler.go
+1
-1
No files found.
pkg/services/alerting/eval_context.go
View file @
7ddd625e
...
...
@@ -28,36 +28,46 @@ type EvalContext struct {
ImageOnDiskPath
string
}
func
(
a
*
EvalContext
)
GetDurationMs
()
float64
{
return
float64
(
a
.
EndTime
.
Nanosecond
()
-
a
.
StartTime
.
Nanosecond
())
/
float64
(
1000000
)
type
StateDescription
struct
{
Color
string
Text
string
Data
string
}
func
(
c
*
EvalContext
)
GetColor
()
string
{
if
!
c
.
Firing
{
return
"#36a64f"
func
(
c
*
EvalContext
)
GetStateModel
()
*
StateDescription
{
if
c
.
Error
!=
nil
{
return
&
StateDescription
{
Color
:
"#D63232"
,
Text
:
"EXECUTION ERROR"
,
}
if
c
.
Rule
.
Severity
==
m
.
AlertSeverityWarning
{
return
"#fd821b"
}
else
{
return
"#D63232"
}
}
func
(
c
*
EvalContext
)
GetStateText
()
string
{
if
!
c
.
Firing
{
return
"OK"
return
&
StateDescription
{
Color
:
"#36a64f"
,
Text
:
"OK"
,
}
}
if
c
.
Rule
.
Severity
==
m
.
AlertSeverityWarning
{
return
"WARNING"
return
&
StateDescription
{
Color
:
"#fd821b"
,
Text
:
"WARNING"
,
}
}
else
{
return
"CRITICAL"
return
&
StateDescription
{
Color
:
"#D63232"
,
Text
:
"CRITICAL"
,
}
}
}
func
(
a
*
EvalContext
)
GetDurationMs
()
float64
{
return
float64
(
a
.
EndTime
.
Nanosecond
()
-
a
.
StartTime
.
Nanosecond
())
/
float64
(
1000000
)
}
func
(
c
*
EvalContext
)
GetNotificationTitle
()
string
{
return
"["
+
c
.
GetState
Text
()
+
"] "
+
c
.
Rule
.
Name
return
"["
+
c
.
GetState
Model
()
.
Text
+
"] "
+
c
.
Rule
.
Name
}
func
(
c
*
EvalContext
)
getDashboardSlug
()
(
string
,
error
)
{
...
...
pkg/services/alerting/notifier.go
View file @
7ddd625e
...
...
@@ -48,7 +48,6 @@ func (n *RootNotifier) Notify(context *EvalContext) {
for
_
,
notifier
:=
range
notifiers
{
n
.
log
.
Info
(
"Sending notification"
,
"firing"
,
context
.
Firing
,
"type"
,
notifier
.
GetType
())
go
notifier
.
Notify
(
context
)
}
}
...
...
pkg/services/alerting/notifiers/email.go
View file @
7ddd625e
...
...
@@ -54,7 +54,7 @@ func (this *EmailNotifier) Notify(context *alerting.EvalContext) {
"State"
:
context
.
Rule
.
State
,
"Name"
:
context
.
Rule
.
Name
,
"Severity"
:
context
.
Rule
.
Severity
,
"SeverityColor"
:
context
.
Get
Color
()
,
"SeverityColor"
:
context
.
Get
StateModel
()
.
Color
,
"Message"
:
context
.
Rule
.
Message
,
"RuleUrl"
:
ruleUrl
,
"ImageLink"
:
context
.
ImagePublicUrl
,
...
...
pkg/services/alerting/notifiers/slack.go
View file @
7ddd625e
...
...
@@ -61,13 +61,26 @@ func (this *SlackNotifier) Notify(context *alerting.EvalContext) {
}
}
if
context
.
Error
!=
nil
{
fields
=
append
(
fields
,
map
[
string
]
interface
{}{
"title"
:
"Error message"
,
"value"
:
context
.
Error
.
Error
(),
"short"
:
false
,
})
}
message
:=
""
if
context
.
Rule
.
State
!=
m
.
AlertStateOK
{
//dont add message when going back to alert state ok.
message
=
context
.
Rule
.
Message
}
body
:=
map
[
string
]
interface
{}{
"attachments"
:
[]
map
[
string
]
interface
{}{
{
"color"
:
context
.
Get
Color
()
,
"color"
:
context
.
Get
StateModel
()
.
Color
,
"title"
:
context
.
GetNotificationTitle
(),
"title_link"
:
ruleUrl
,
"text"
:
context
.
Rule
.
M
essage
,
"text"
:
m
essage
,
"fields"
:
fields
,
"image_url"
:
context
.
ImagePublicUrl
,
"footer"
:
"Grafana v"
+
setting
.
BuildVersion
,
...
...
pkg/services/alerting/result_handler.go
View file @
7ddd625e
...
...
@@ -65,7 +65,7 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
Type
:
annotations
.
AlertType
,
AlertId
:
ctx
.
Rule
.
Id
,
Title
:
ctx
.
Rule
.
Name
,
Text
:
ctx
.
GetState
Text
()
,
Text
:
ctx
.
GetState
Model
()
.
Text
,
NewState
:
string
(
ctx
.
Rule
.
State
),
PrevState
:
string
(
oldState
),
Timestamp
:
time
.
Now
(),
...
...
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