From b46cbc5fbe13bac36746520ec54a176bb5c1aa12 Mon Sep 17 00:00:00 2001 From: ichekrygin Date: Sun, 30 Oct 2016 11:14:54 -0700 Subject: [PATCH] Add option to alert on ExecutionError --- pkg/services/alerting/notifiers/victorops.go | 22 ++++++++++++++----- .../alerting/partials/notification_edit.html | 9 ++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/pkg/services/alerting/notifiers/victorops.go b/pkg/services/alerting/notifiers/victorops.go index 4d22de3ab9a..7809eceadac 100644 --- a/pkg/services/alerting/notifiers/victorops.go +++ b/pkg/services/alerting/notifiers/victorops.go @@ -27,10 +27,13 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e return nil, alerting.ValidationError{Reason: "Could not find victorops url property in settings"} } + alertOnExecError := model.Settings.Get("alertOnExecError").MustBool() + return &VictoropsNotifier{ - NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings), - URL: url, - log: log.New("alerting.notifier.victorops"), + NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings), + URL: url, + AlertOnExecError: alertOnExecError, + log: log.New("alerting.notifier.victorops"), }, nil } @@ -39,13 +42,14 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e // Victorops specifications (http://victorops.force.com/knowledgebase/articles/Integration/Alert-Ingestion-API-Documentation/) type VictoropsNotifier struct { NotifierBase - URL string - log log.Logger + URL string + AlertOnExecError bool + log log.Logger } // 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.Name) + this.log.Info("Executing victorops notification", "ruleId", evalContext.Rule.Id, "notification", this.Name, "url", this.URL, "foo", this.AlertOnExecError) metrics.M_Alerting_Notification_Sent_Victorops.Inc(1) fields := make([]map[string]interface{}, 0) @@ -74,6 +78,12 @@ func (this *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error { messageType = AlertStateCritical } + if evalContext.Rule.State == models.AlertStateExecError && !this.AlertOnExecError { + return nil + } else { + return nil + } + body := map[string]interface{}{ "message_type": messageType, "entity_id": evalContext.Rule.Name, diff --git a/public/app/features/alerting/partials/notification_edit.html b/public/app/features/alerting/partials/notification_edit.html index ac4afbf56fc..23840c1310c 100644 --- a/public/app/features/alerting/partials/notification_edit.html +++ b/public/app/features/alerting/partials/notification_edit.html @@ -93,6 +93,15 @@ Url +
+ + +