feat(alerting): working on alert notification and image rendering
This commit is contained in:
@@ -1,20 +1 @@
|
||||
package notifiers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
func getRuleLink(rule *alerting.Rule) (string, error) {
|
||||
slugQuery := &m.GetDashboardSlugByIdQuery{Id: rule.DashboardId}
|
||||
if err := bus.Dispatch(slugQuery); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ruleLink := fmt.Sprintf("%sdashboard/db/%s?fullscreen&edit&tab=alert&panelId=%d", setting.AppUrl, slugQuery.Result, rule.PanelId)
|
||||
return ruleLink, nil
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
|
||||
func (this *EmailNotifier) Notify(context *alerting.EvalContext) {
|
||||
this.log.Info("Sending alert notification to", "addresses", this.Addresses)
|
||||
|
||||
ruleLink, err := getRuleLink(context.Rule)
|
||||
ruleUrl, err := context.GetRuleUrl()
|
||||
if err != nil {
|
||||
this.log.Error("Failed get rule link", "error", err)
|
||||
return
|
||||
@@ -50,7 +50,7 @@ func (this *EmailNotifier) Notify(context *alerting.EvalContext) {
|
||||
"RuleState": context.Rule.State,
|
||||
"RuleName": context.Rule.Name,
|
||||
"Severity": context.Rule.Severity,
|
||||
"RuleLink": ruleLink,
|
||||
"RuleUrl": ruleUrl,
|
||||
},
|
||||
To: this.Addresses,
|
||||
Template: "alert_notification.html",
|
||||
|
||||
@@ -41,7 +41,7 @@ func (this *SlackNotifier) Notify(context *alerting.EvalContext) {
|
||||
|
||||
rule := context.Rule
|
||||
|
||||
ruleLink, err := getRuleLink(rule)
|
||||
ruleUrl, err := context.GetRuleUrl()
|
||||
if err != nil {
|
||||
this.log.Error("Failed get rule link", "error", err)
|
||||
return
|
||||
@@ -69,10 +69,10 @@ func (this *SlackNotifier) Notify(context *alerting.EvalContext) {
|
||||
// "author_link": "http://flickr.com/bobby/",
|
||||
// "author_icon": "http://flickr.com/icons/bobby.jpg",
|
||||
"title": "[" + context.GetStateText() + "] " + rule.Name,
|
||||
"title_link": ruleLink,
|
||||
"title_link": ruleUrl,
|
||||
// "text": "Optional text that appears within the attachment",
|
||||
"fields": fields,
|
||||
// "image_url": "http://my-website.com/path/to/image.jpg",
|
||||
"fields": fields,
|
||||
"image_url": context.ImagePublicUrl,
|
||||
// "thumb_url": "http://example.com/path/to/thumb.png",
|
||||
"footer": "Grafana v4.0.0",
|
||||
"footer_icon": "http://grafana.org/assets/img/fav32.png",
|
||||
|
||||
Reference in New Issue
Block a user