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
ab5bc1bf
Commit
ab5bc1bf
authored
Oct 05, 2017
by
Carl Bergquist
Committed by
GitHub
Oct 05, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9111 from eloo/feature/enhance_hipchat_card
Feature/enhance hipchat card
parents
6979dbd9
6a030b2e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
21 deletions
+40
-21
.editorconfig
+6
-6
pkg/services/alerting/notifiers/hipchat.go
+34
-15
No files found.
.editorconfig
View file @
ab5bc1bf
# http://editorconfig.org
# http://editorconfig.org
root = true
root = true
[*
.go
]
[*]
indent_style =
tab
indent_style =
space
indent_size =
4
indent_size =
2
charset = utf-8
charset = utf-8
trim_trailing_whitespace = true
trim_trailing_whitespace = true
insert_final_newline = true
insert_final_newline = true
[*]
[*
.go
]
indent_style =
space
indent_style =
tab
indent_size =
2
indent_size =
4
charset = utf-8
charset = utf-8
trim_trailing_whitespace = true
trim_trailing_whitespace = true
insert_final_newline = true
insert_final_newline = true
...
...
pkg/services/alerting/notifiers/hipchat.go
View file @
ab5bc1bf
...
@@ -84,15 +84,17 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
...
@@ -84,15 +84,17 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
return
err
return
err
}
}
message
:=
evalContext
.
GetNotificationTitle
()
+
" in state "
+
evalContext
.
GetStateModel
()
.
Text
+
"<br><a href="
+
ruleUrl
+
">Check Dashboard</a>"
attributes
:=
make
([]
map
[
string
]
interface
{},
0
)
fields
:=
make
([]
map
[
string
]
interface
{},
0
)
message
+=
"<br>"
for
index
,
evt
:=
range
evalContext
.
EvalMatches
{
for
index
,
evt
:=
range
evalContext
.
EvalMatches
{
message
+=
evt
.
Metric
+
" :: "
+
strconv
.
FormatFloat
(
evt
.
Value
.
Float64
,
'f'
,
-
1
,
64
)
+
"<br>"
metricName
:=
evt
.
Metric
fields
=
append
(
fields
,
map
[
string
]
interface
{}{
if
len
(
metricName
)
>
50
{
"title"
:
evt
.
Metric
,
metricName
=
metricName
[
:
50
]
"value"
:
evt
.
Value
,
}
"short"
:
true
,
attributes
=
append
(
attributes
,
map
[
string
]
interface
{}{
"label"
:
metricName
,
"value"
:
map
[
string
]
interface
{}{
"label"
:
strconv
.
FormatFloat
(
evt
.
Value
.
Float64
,
'f'
,
-
1
,
64
),
},
})
})
if
index
>
maxFieldCount
{
if
index
>
maxFieldCount
{
break
break
...
@@ -100,16 +102,23 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
...
@@ -100,16 +102,23 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
}
}
if
evalContext
.
Error
!=
nil
{
if
evalContext
.
Error
!=
nil
{
fields
=
append
(
fields
,
map
[
string
]
interface
{}{
attributes
=
append
(
attributes
,
map
[
string
]
interface
{}{
"title"
:
"Error message"
,
"label"
:
"Error message"
,
"value"
:
evalContext
.
Error
.
Error
(),
"value"
:
map
[
string
]
interface
{}{
"short"
:
false
,
"label"
:
evalContext
.
Error
.
Error
(),
},
})
})
}
}
message
:=
""
if
evalContext
.
Rule
.
State
!=
models
.
AlertStateOK
{
//dont add message when going back to alert state ok.
if
evalContext
.
Rule
.
State
!=
models
.
AlertStateOK
{
//dont add message when going back to alert state ok.
message
+=
" "
+
evalContext
.
Rule
.
Message
message
+=
" "
+
evalContext
.
Rule
.
Message
}
}
if
message
==
""
{
message
=
evalContext
.
GetNotificationTitle
()
+
" in state "
+
evalContext
.
GetStateModel
()
.
Text
}
//HipChat has a set list of colors
//HipChat has a set list of colors
var
color
string
var
color
string
switch
evalContext
.
Rule
.
State
{
switch
evalContext
.
Rule
.
State
{
...
@@ -123,15 +132,24 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
...
@@ -123,15 +132,24 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
// Add a card with link to the dashboard
// Add a card with link to the dashboard
card
:=
map
[
string
]
interface
{}{
card
:=
map
[
string
]
interface
{}{
"style"
:
"
link
"
,
"style"
:
"
application
"
,
"url"
:
ruleUrl
,
"url"
:
ruleUrl
,
"id"
:
"1"
,
"id"
:
"1"
,
"title"
:
evalContext
.
GetNotificationTitle
(),
"title"
:
evalContext
.
GetNotificationTitle
(),
"description"
:
evalContext
.
GetNotificationTitle
()
+
" in state "
+
evalContext
.
GetStateModel
()
.
Text
,
"description"
:
message
,
"icon"
:
map
[
string
]
interface
{}{
"icon"
:
map
[
string
]
interface
{}{
"url"
:
"https://grafana.com/assets/img/fav32.png"
,
"url"
:
"https://grafana.com/assets/img/fav32.png"
,
},
},
"date"
:
evalContext
.
EndTime
.
Unix
(),
"date"
:
evalContext
.
EndTime
.
Unix
(),
"attributes"
:
attributes
,
}
if
evalContext
.
ImagePublicUrl
!=
""
{
card
[
"thumbnail"
]
=
map
[
string
]
interface
{}{
"url"
:
evalContext
.
ImagePublicUrl
,
"url@2x"
:
evalContext
.
ImagePublicUrl
,
"width"
:
1193
,
"height"
:
564
,
}
}
}
body
:=
map
[
string
]
interface
{}{
body
:=
map
[
string
]
interface
{}{
...
@@ -144,6 +162,7 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
...
@@ -144,6 +162,7 @@ func (this *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
hipUrl
:=
fmt
.
Sprintf
(
"%s/v2/room/%s/notification?auth_token=%s"
,
this
.
Url
,
this
.
RoomId
,
this
.
ApiKey
)
hipUrl
:=
fmt
.
Sprintf
(
"%s/v2/room/%s/notification?auth_token=%s"
,
this
.
Url
,
this
.
RoomId
,
this
.
ApiKey
)
data
,
_
:=
json
.
Marshal
(
&
body
)
data
,
_
:=
json
.
Marshal
(
&
body
)
this
.
log
.
Info
(
"Request payload"
,
"json"
,
string
(
data
))
cmd
:=
&
models
.
SendWebhookSync
{
Url
:
hipUrl
,
Body
:
string
(
data
)}
cmd
:=
&
models
.
SendWebhookSync
{
Url
:
hipUrl
,
Body
:
string
(
data
)}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
...
...
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