From 8f0d51171d78faea62e1c95d7dcc723dfc076d16 Mon Sep 17 00:00:00 2001 From: ichekrygin Date: Wed, 16 Nov 2016 16:13:33 -0800 Subject: [PATCH] Resolve rebase w/ upstream conflicts. Remove: `Alert on Exec Error` (no longer needed) Add: `ruleUrl` to VictorOps message body. --- pkg/services/alerting/notifiers/victorops.go | 18 ++++++++++-------- .../alerting/partials/notification_edit.html | 9 --------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pkg/services/alerting/notifiers/victorops.go b/pkg/services/alerting/notifiers/victorops.go index bf0042a53e5..d4dfa8c6678 100644 --- a/pkg/services/alerting/notifiers/victorops.go +++ b/pkg/services/alerting/notifiers/victorops.go @@ -49,9 +49,15 @@ type VictoropsNotifier struct { // Notify sends notification to Victorops via POST to URL endpoint func (this *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error { - this.log.Info("Executing victorops notification", "ruleId", evalContext.Rule.Id, "notification") + this.log.Info("Executing victorops notification", "ruleId", evalContext.Rule.Id, "notification", this.Name) metrics.M_Alerting_Notification_Sent_Victorops.Inc(1) + ruleUrl, err := evalContext.GetRuleUrl() + if err != nil { + this.log.Error("Failed get rule link", "error", err) + return err + } + fields := make([]map[string]interface{}, 0) fieldLimitCount := 4 for index, evt := range evalContext.EvalMatches { @@ -78,23 +84,19 @@ func (this *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error { messageType = AlertStateCritical } - if evalContext.Rule.State == models.AlertStateExecError && !this.AlertOnExecError { - return nil - } - body := map[string]interface{}{ "message_type": messageType, "entity_id": evalContext.Rule.Name, "timestamp": time.Now().Unix(), "state_start_time": evalContext.StartTime.Unix(), - "state_message": evalContext.Rule.Message, + "state_message": evalContext.Rule.Message + "\n" + ruleUrl, "monitoring_tool": "Grafana v" + setting.BuildVersion, } data, _ := json.Marshal(&body) - cmd := &models.SendWebhook{Url: this.URL, Body: string(data)} + cmd := &models.SendWebhookSync{Url: this.URL, Body: string(data)} - if err := bus.Dispatch(cmd); err != nil { + if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { this.log.Error("Failed to send victorops notification", "error", err, "webhook", this.Name) } diff --git a/public/app/features/alerting/partials/notification_edit.html b/public/app/features/alerting/partials/notification_edit.html index 23840c1310c..ac4afbf56fc 100644 --- a/public/app/features/alerting/partials/notification_edit.html +++ b/public/app/features/alerting/partials/notification_edit.html @@ -93,15 +93,6 @@ Url -
- - -