Add option to alert on ExecutionError

This commit is contained in:
ichekrygin 2016-10-30 11:14:54 -07:00
parent 4ca304b756
commit b46cbc5fbe
2 changed files with 25 additions and 6 deletions

View File

@ -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,

View File

@ -93,6 +93,15 @@
<span class="gf-form-label width-6">Url</span>
<input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.url" placeholder="Victorops url"></input>
</div>
<div class="gf-form">
<gf-form-switch
class="gf-form"
label="Alert on Exec Error"
label-class="width-12"
checked="ctrl.model.settings.alertOnExecError"
tooltip="Trigger incident on Execution Error">
</gf-form-switch>
</div>
</div>
<div class="gf-form-group section" ng-if="ctrl.model.type === 'email'">