Commit 9fa551cc by Rob Russo Committed by GitHub

Alerting: updating the victorops alerter to handle the no_data alert type (#23761)

parent 54ee4f4f
...@@ -14,6 +14,8 @@ import ( ...@@ -14,6 +14,8 @@ import (
// AlertStateCritical - Victorops uses "CRITICAL" string to indicate "Alerting" state // AlertStateCritical - Victorops uses "CRITICAL" string to indicate "Alerting" state
const AlertStateCritical = "CRITICAL" const AlertStateCritical = "CRITICAL"
// AlertStateWarning - VictorOps "WARNING" message type
const AlertStateWarning = "WARNING"
const alertStateRecovery = "RECOVERY" const alertStateRecovery = "RECOVERY"
func init() { func init() {
...@@ -29,6 +31,13 @@ func init() { ...@@ -29,6 +31,13 @@ func init() {
<input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.url" placeholder="VictorOps url"></input> <input type="text" required class="gf-form-input max-width-30" ng-model="ctrl.model.settings.url" placeholder="VictorOps url"></input>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-10">No Data Alert Type</span>
<div class="gf-form-select-wrapper width-14">
<select class="gf-form-input" ng-model="ctrl.model.settings.noDataAlertType" ng-options="t for t in ['CRITICAL', 'WARNING']" ng-init="ctrl.model.settings.noDataAlertType=ctrl.model.settings.noDataAlertType || '` + AlertStateWarning + `'">
</select>
</div>
</div>
<div class="gf-form">
<gf-form-switch <gf-form-switch
class="gf-form" class="gf-form"
label="Auto resolve incidents" label="Auto resolve incidents"
...@@ -49,12 +58,14 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e ...@@ -49,12 +58,14 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e
if url == "" { if url == "" {
return nil, alerting.ValidationError{Reason: "Could not find victorops url property in settings"} return nil, alerting.ValidationError{Reason: "Could not find victorops url property in settings"}
} }
noDataAlertType := model.Settings.Get("noDataAlertType").MustString(AlertStateWarning)
return &VictoropsNotifier{ return &VictoropsNotifier{
NotifierBase: NewNotifierBase(model), NotifierBase: NewNotifierBase(model),
URL: url, URL: url,
AutoResolve: autoResolve, NoDataAlertType: noDataAlertType,
log: log.New("alerting.notifier.victorops"), AutoResolve: autoResolve,
log: log.New("alerting.notifier.victorops"),
}, nil }, nil
} }
...@@ -63,9 +74,10 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e ...@@ -63,9 +74,10 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e
// Victorops specifications (http://victorops.force.com/knowledgebase/articles/Integration/Alert-Ingestion-API-Documentation/) // Victorops specifications (http://victorops.force.com/knowledgebase/articles/Integration/Alert-Ingestion-API-Documentation/)
type VictoropsNotifier struct { type VictoropsNotifier struct {
NotifierBase NotifierBase
URL string URL string
AutoResolve bool NoDataAlertType string
log log.Logger AutoResolve bool
log log.Logger
} }
// Notify sends notification to Victorops via POST to URL endpoint // Notify sends notification to Victorops via POST to URL endpoint
...@@ -83,9 +95,10 @@ func (vn *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error { ...@@ -83,9 +95,10 @@ func (vn *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error {
return nil return nil
} }
messageType := evalContext.Rule.State messageType := AlertStateCritical // Default to alerting and change based on state checks (Ensures string type)
if evalContext.Rule.State == models.AlertStateAlerting { // translate 'Alerting' to 'CRITICAL' (Victorops analog)
messageType = AlertStateCritical if evalContext.Rule.State == models.AlertStateNoData { // translate 'NODATA' to set alert
messageType = vn.NoDataAlertType
} }
if evalContext.Rule.State == models.AlertStateOK { if evalContext.Rule.State == models.AlertStateOK {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment