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
63fdffe8
Commit
63fdffe8
authored
Nov 07, 2018
by
Andrey Kaipov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #13993 - adds more options for Slack notifications
parent
3b4d8c9b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
1 deletions
+61
-1
pkg/services/alerting/notifiers/slack.go
+51
-0
pkg/services/alerting/notifiers/slack_test.go
+10
-1
No files found.
pkg/services/alerting/notifiers/slack.go
View file @
63fdffe8
...
...
@@ -40,6 +40,39 @@ func init() {
</info-popover>
</div>
<div class="gf-form max-width-30">
<span class="gf-form-label width-6">Username</span>
<input type="text"
class="gf-form-input max-width-30"
ng-model="ctrl.model.settings.username"
data-placement="right">
</input>
<info-popover mode="right-absolute">
Set the username for the bot's message
</info-popover>
</div>
<div class="gf-form max-width-30">
<span class="gf-form-label width-6">Icon emoji</span>
<input type="text"
class="gf-form-input max-width-30"
ng-model="ctrl.model.settings.icon_emoji"
data-placement="right">
</input>
<info-popover mode="right-absolute">
Provide an emoji to use as the icon for the bot's message. Overrides the icon URL
</info-popover>
</div>
<div class="gf-form max-width-30">
<span class="gf-form-label width-6">Icon URL</span>
<input type="text"
class="gf-form-input max-width-30"
ng-model="ctrl.model.settings.icon_url"
data-placement="right">
</input>
<info-popover mode="right-absolute">
Provide a URL to an image to use as the icon for the bot's message
</info-popover>
</div>
<div class="gf-form max-width-30">
<span class="gf-form-label width-6">Mention</span>
<input type="text"
class="gf-form-input max-width-30"
...
...
@@ -73,6 +106,9 @@ func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
recipient
:=
model
.
Settings
.
Get
(
"recipient"
)
.
MustString
()
username
:=
model
.
Settings
.
Get
(
"username"
)
.
MustString
()
iconEmoji
:=
model
.
Settings
.
Get
(
"icon_emoji"
)
.
MustString
()
iconUrl
:=
model
.
Settings
.
Get
(
"icon_url"
)
.
MustString
()
mention
:=
model
.
Settings
.
Get
(
"mention"
)
.
MustString
()
token
:=
model
.
Settings
.
Get
(
"token"
)
.
MustString
()
uploadImage
:=
model
.
Settings
.
Get
(
"uploadImage"
)
.
MustBool
(
true
)
...
...
@@ -81,6 +117,9 @@ func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
Recipient
:
recipient
,
Username
:
username
,
IconEmoji
:
iconEmoji
,
IconUrl
:
iconUrl
,
Mention
:
mention
,
Token
:
token
,
Upload
:
uploadImage
,
...
...
@@ -92,6 +131,9 @@ type SlackNotifier struct {
NotifierBase
Url
string
Recipient
string
Username
string
IconEmoji
string
IconUrl
string
Mention
string
Token
string
Upload
bool
...
...
@@ -160,6 +202,15 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
if
this
.
Recipient
!=
""
{
body
[
"channel"
]
=
this
.
Recipient
}
if
this
.
Username
!=
""
{
body
[
"username"
]
=
this
.
Username
}
if
this
.
IconEmoji
!=
""
{
body
[
"icon_emoji"
]
=
this
.
IconEmoji
}
if
this
.
IconUrl
!=
""
{
body
[
"icon_url"
]
=
this
.
IconUrl
}
data
,
_
:=
json
.
Marshal
(
&
body
)
cmd
:=
&
m
.
SendWebhookSync
{
Url
:
this
.
Url
,
Body
:
string
(
data
)}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
...
...
pkg/services/alerting/notifiers/slack_test.go
View file @
63fdffe8
...
...
@@ -47,15 +47,21 @@ func TestSlackNotifier(t *testing.T) {
So
(
slackNotifier
.
Type
,
ShouldEqual
,
"slack"
)
So
(
slackNotifier
.
Url
,
ShouldEqual
,
"http://google.com"
)
So
(
slackNotifier
.
Recipient
,
ShouldEqual
,
""
)
So
(
slackNotifier
.
Username
,
ShouldEqual
,
""
)
So
(
slackNotifier
.
IconEmoji
,
ShouldEqual
,
""
)
So
(
slackNotifier
.
IconUrl
,
ShouldEqual
,
""
)
So
(
slackNotifier
.
Mention
,
ShouldEqual
,
""
)
So
(
slackNotifier
.
Token
,
ShouldEqual
,
""
)
})
Convey
(
"from settings with Recipient, Mention, and Token"
,
func
()
{
Convey
(
"from settings with Recipient,
Username, IconEmoji, IconUrl,
Mention, and Token"
,
func
()
{
json
:=
`
{
"url": "http://google.com",
"recipient": "#ds-opentsdb",
"username": "Grafana Alerts",
"icon_emoji": ":smile:",
"icon_url": "https://grafana.com/img/fav32.png",
"mention": "@carl",
"token": "xoxb-XXXXXXXX-XXXXXXXX-XXXXXXXXXX"
}`
...
...
@@ -75,6 +81,9 @@ func TestSlackNotifier(t *testing.T) {
So
(
slackNotifier
.
Type
,
ShouldEqual
,
"slack"
)
So
(
slackNotifier
.
Url
,
ShouldEqual
,
"http://google.com"
)
So
(
slackNotifier
.
Recipient
,
ShouldEqual
,
"#ds-opentsdb"
)
So
(
slackNotifier
.
Username
,
ShouldEqual
,
"Grafana Alerts"
)
So
(
slackNotifier
.
IconEmoji
,
ShouldEqual
,
":smile:"
)
So
(
slackNotifier
.
IconUrl
,
ShouldEqual
,
"https://grafana.com/img/fav32.png"
)
So
(
slackNotifier
.
Mention
,
ShouldEqual
,
"@carl"
)
So
(
slackNotifier
.
Token
,
ShouldEqual
,
"xoxb-XXXXXXXX-XXXXXXXX-XXXXXXXXXX"
)
})
...
...
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