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
ca6151e2
Commit
ca6151e2
authored
May 23, 2019
by
Abhilash Gnan
Committed by
Carl Bergquist
May 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alerting: Support for configuring content field for Discord alert notifier (#17017)
parent
a9c94ec9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
pkg/services/alerting/notifiers/discord.go
+21
-3
pkg/services/alerting/notifiers/discord_test.go
+3
-1
No files found.
pkg/services/alerting/notifiers/discord.go
View file @
ca6151e2
...
...
@@ -24,15 +24,27 @@ func init() {
Factory
:
NewDiscordNotifier
,
OptionsTemplate
:
`
<h3 class="page-heading">Discord settings</h3>
<div class="gf-form">
<span class="gf-form-label width-14">Webhook URL</span>
<input type="text" required class="gf-form-input max-width-22" ng-model="ctrl.model.settings.url" placeholder="Discord webhook URL"></input>
<div class="gf-form max-width-30">
<span class="gf-form-label width-10">Message Content</span>
<input type="text"
class="gf-form-input max-width-30"
ng-model="ctrl.model.settings.content"
data-placement="right">
</input>
<info-popover mode="right-absolute">
Mention a group using @ or a user using <@ID> when notifying in a channel
</info-popover>
</div>
<div class="gf-form max-width-30">
<span class="gf-form-label width-10">Webhook URL</span>
<input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.url" placeholder="Discord webhook URL"></input>
</div>
`
,
})
}
func
NewDiscordNotifier
(
model
*
models
.
AlertNotification
)
(
alerting
.
Notifier
,
error
)
{
content
:=
model
.
Settings
.
Get
(
"content"
)
.
MustString
()
url
:=
model
.
Settings
.
Get
(
"url"
)
.
MustString
()
if
url
==
""
{
return
nil
,
alerting
.
ValidationError
{
Reason
:
"Could not find webhook url property in settings"
}
...
...
@@ -40,6 +52,7 @@ func NewDiscordNotifier(model *models.AlertNotification) (alerting.Notifier, err
return
&
DiscordNotifier
{
NotifierBase
:
NewNotifierBase
(
model
),
Content
:
content
,
WebhookURL
:
url
,
log
:
log
.
New
(
"alerting.notifier.discord"
),
},
nil
...
...
@@ -47,6 +60,7 @@ func NewDiscordNotifier(model *models.AlertNotification) (alerting.Notifier, err
type
DiscordNotifier
struct
{
NotifierBase
Content
string
WebhookURL
string
log
log
.
Logger
}
...
...
@@ -63,6 +77,10 @@ func (this *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
bodyJSON
:=
simplejson
.
New
()
bodyJSON
.
Set
(
"username"
,
"Grafana"
)
if
this
.
Content
!=
""
{
bodyJSON
.
Set
(
"content"
,
this
.
Content
)
}
fields
:=
make
([]
map
[
string
]
interface
{},
0
)
for
_
,
evt
:=
range
evalContext
.
EvalMatches
{
...
...
pkg/services/alerting/notifiers/discord_test.go
View file @
ca6151e2
...
...
@@ -29,7 +29,8 @@ func TestDiscordNotifier(t *testing.T) {
Convey
(
"settings should trigger incident"
,
func
()
{
json
:=
`
{
"url": "https://web.hook/"
"content": "@everyone Please check this notification",
"url": "https://web.hook/"
}`
settingsJSON
,
_
:=
simplejson
.
NewJson
([]
byte
(
json
))
...
...
@@ -45,6 +46,7 @@ func TestDiscordNotifier(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
discordNotifier
.
Name
,
ShouldEqual
,
"discord_testing"
)
So
(
discordNotifier
.
Type
,
ShouldEqual
,
"discord"
)
So
(
discordNotifier
.
Content
,
ShouldEqual
,
"@everyone Please check this notification"
)
So
(
discordNotifier
.
WebhookURL
,
ShouldEqual
,
"https://web.hook/"
)
})
})
...
...
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