mirror of
https://github.com/grafana/grafana.git
synced 2025-01-27 16:57:14 -06:00
Alerting: updating the victorops alerter to handle the no_data alert type (#23761)
This commit is contained in:
parent
54ee4f4f72
commit
9fa551cc32
@ -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() {
|
||||
@ -28,6 +30,13 @@ func init() {
|
||||
<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">
|
||||
<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"
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user