Commit bcac76f5 by zabullet Committed by Marcus Efraimsson

Alerting: Enable setting of OpsGenie priority via a tag (#21298)

OpsGenie's model works heavily off of the priority of an alert, 
e.g. routing and escalation. Currently this plugin only supports 
the default "P3".
Setting a tag og_priority to the correct P-value, e.g. P1, P2, P3, 
P4 or P5, will call the OpsGenie API with the correct priority value 
set.
parent abc806e1
...@@ -430,6 +430,7 @@ The following sections detail the supported settings for each alert notification ...@@ -430,6 +430,7 @@ The following sections detail the supported settings for each alert notification
| apiKey | | apiKey |
| apiUrl | | apiUrl |
| autoClose | | autoClose |
| overridePriority |
#### Alert notification `telegram` #### Alert notification `telegram`
......
...@@ -36,7 +36,16 @@ func init() { ...@@ -36,7 +36,16 @@ func init() {
tooltip="Automatically close alerts in OpsGenie once the alert goes back to ok."> tooltip="Automatically close alerts in OpsGenie once the alert goes back to ok.">
</gf-form-switch> </gf-form-switch>
</div> </div>
`, <div class="gf-form">
<gf-form-switch
class="gf-form"
label="Override priority"
label-class="width-14"
checked="ctrl.model.settings.overridePriority"
tooltip="Allow the alert priority to be set using the og_priority tag">
</gf-form-switch>
</div>
`,
}) })
} }
...@@ -47,6 +56,7 @@ var ( ...@@ -47,6 +56,7 @@ var (
// NewOpsGenieNotifier is the constructor for OpsGenie. // NewOpsGenieNotifier is the constructor for OpsGenie.
func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) { func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, error) {
autoClose := model.Settings.Get("autoClose").MustBool(true) autoClose := model.Settings.Get("autoClose").MustBool(true)
overridePriority := model.Settings.Get("overridePriority").MustBool(true)
apiKey := model.Settings.Get("apiKey").MustString() apiKey := model.Settings.Get("apiKey").MustString()
apiURL := model.Settings.Get("apiUrl").MustString() apiURL := model.Settings.Get("apiUrl").MustString()
if apiKey == "" { if apiKey == "" {
...@@ -57,11 +67,12 @@ func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, er ...@@ -57,11 +67,12 @@ func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, er
} }
return &OpsGenieNotifier{ return &OpsGenieNotifier{
NotifierBase: NewNotifierBase(model), NotifierBase: NewNotifierBase(model),
APIKey: apiKey, APIKey: apiKey,
APIUrl: apiURL, APIUrl: apiURL,
AutoClose: autoClose, AutoClose: autoClose,
log: log.New("alerting.notifier.opsgenie"), OverridePriority: overridePriority,
log: log.New("alerting.notifier.opsgenie"),
}, nil }, nil
} }
...@@ -69,10 +80,11 @@ func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, er ...@@ -69,10 +80,11 @@ func NewOpsGenieNotifier(model *models.AlertNotification) (alerting.Notifier, er
// alert notifications to OpsGenie // alert notifications to OpsGenie
type OpsGenieNotifier struct { type OpsGenieNotifier struct {
NotifierBase NotifierBase
APIKey string APIKey string
APIUrl string APIUrl string
AutoClose bool AutoClose bool
log log.Logger OverridePriority bool
log log.Logger
} }
// Notify sends an alert notification to OpsGenie. // Notify sends an alert notification to OpsGenie.
...@@ -124,7 +136,14 @@ func (on *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) error ...@@ -124,7 +136,14 @@ func (on *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) error
} else { } else {
tags = append(tags, tag.Key) tags = append(tags, tag.Key)
} }
if tag.Key == "og_priority" {
if on.OverridePriority {
validPriorities := map[string]bool{"P1": true, "P2": true, "P3": true, "P4": true, "P5": true}
if validPriorities[tag.Value] {
bodyJSON.Set("priority", tag.Value)
}
}
}
} }
bodyJSON.Set("tags", tags) bodyJSON.Set("tags", tags)
......
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