|
@@ -24,15 +24,27 @@ func init() {
|
|
|
Factory: NewDiscordNotifier,
|
|
Factory: NewDiscordNotifier,
|
|
|
OptionsTemplate: `
|
|
OptionsTemplate: `
|
|
|
<h3 class="page-heading">Discord settings</h3>
|
|
<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>
|
|
</div>
|
|
|
`,
|
|
`,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func NewDiscordNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
|
|
func NewDiscordNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
|
|
|
|
|
+ content := model.Settings.Get("content").MustString()
|
|
|
url := model.Settings.Get("url").MustString()
|
|
url := model.Settings.Get("url").MustString()
|
|
|
if url == "" {
|
|
if url == "" {
|
|
|
return nil, alerting.ValidationError{Reason: "Could not find webhook url property in settings"}
|
|
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{
|
|
return &DiscordNotifier{
|
|
|
NotifierBase: NewNotifierBase(model),
|
|
NotifierBase: NewNotifierBase(model),
|
|
|
|
|
+ Content: content,
|
|
|
WebhookURL: url,
|
|
WebhookURL: url,
|
|
|
log: log.New("alerting.notifier.discord"),
|
|
log: log.New("alerting.notifier.discord"),
|
|
|
}, nil
|
|
}, nil
|
|
@@ -47,6 +60,7 @@ func NewDiscordNotifier(model *models.AlertNotification) (alerting.Notifier, err
|
|
|
|
|
|
|
|
type DiscordNotifier struct {
|
|
type DiscordNotifier struct {
|
|
|
NotifierBase
|
|
NotifierBase
|
|
|
|
|
+ Content string
|
|
|
WebhookURL string
|
|
WebhookURL string
|
|
|
log log.Logger
|
|
log log.Logger
|
|
|
}
|
|
}
|
|
@@ -63,6 +77,10 @@ func (this *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
|
|
|
bodyJSON := simplejson.New()
|
|
bodyJSON := simplejson.New()
|
|
|
bodyJSON.Set("username", "Grafana")
|
|
bodyJSON.Set("username", "Grafana")
|
|
|
|
|
|
|
|
|
|
+ if this.Content != "" {
|
|
|
|
|
+ bodyJSON.Set("content", this.Content)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
fields := make([]map[string]interface{}, 0)
|
|
fields := make([]map[string]interface{}, 0)
|
|
|
|
|
|
|
|
for _, evt := range evalContext.EvalMatches {
|
|
for _, evt := range evalContext.EvalMatches {
|