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 (
// AlertStateCritical - Victorops uses "CRITICAL" string to indicate "Alerting" state
const AlertStateCritical = "CRITICAL"
// AlertStateWarning - VictorOps "WARNING" message type
const AlertStateWarning = "WARNING"
const alertStateRecovery = "RECOVERY"
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>
</div>
<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
class="gf-form"
label="Auto resolve incidents"
......@@ -49,12 +58,14 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e
if url == "" {
return nil, alerting.ValidationError{Reason: "Could not find victorops url property in settings"}
}
noDataAlertType := model.Settings.Get("noDataAlertType").MustString(AlertStateWarning)
return &VictoropsNotifier{
NotifierBase: NewNotifierBase(model),
URL: url,
AutoResolve: autoResolve,
log: log.New("alerting.notifier.victorops"),
NotifierBase: NewNotifierBase(model),
URL: url,
NoDataAlertType: noDataAlertType,
AutoResolve: autoResolve,
log: log.New("alerting.notifier.victorops"),
}, nil
}
......@@ -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/)
type VictoropsNotifier struct {
NotifierBase
URL string
AutoResolve bool
log log.Logger
URL string
NoDataAlertType string
AutoResolve bool
log log.Logger
}
// Notify sends notification to Victorops via POST to URL endpoint
......@@ -83,9 +95,10 @@ func (vn *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error {
return nil
}
messageType := evalContext.Rule.State
if evalContext.Rule.State == models.AlertStateAlerting { // translate 'Alerting' to 'CRITICAL' (Victorops analog)
messageType = AlertStateCritical
messageType := AlertStateCritical // Default to alerting and change based on state checks (Ensures string type)
if evalContext.Rule.State == models.AlertStateNoData { // translate 'NODATA' to set alert
messageType = vn.NoDataAlertType
}
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