diff --git a/pkg/services/alerting/notifiers/opsgenie.go b/pkg/services/alerting/notifiers/opsgenie.go index e67ccfb10e5..5af9fa69611 100644 --- a/pkg/services/alerting/notifiers/opsgenie.go +++ b/pkg/services/alerting/notifiers/opsgenie.go @@ -37,8 +37,7 @@ func init() { } var ( - opsgenieCreateAlertURL string = "https://api.opsgenie.com/v1/json/alert" - opsgenieCloseAlertURL string = "https://api.opsgenie.com/v1/json/alert/close" + opsgenieAlertURL string = "https://api.opsgenie.com/v2/alerts" ) func NewOpsGenieNotifier(model *m.AlertNotification) (alerting.Notifier, error) { @@ -87,7 +86,6 @@ func (this *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) err } bodyJSON := simplejson.New() - bodyJSON.Set("apiKey", this.ApiKey) bodyJSON.Set("message", evalContext.Rule.Name) bodyJSON.Set("source", "Grafana") bodyJSON.Set("alias", "alertId-"+strconv.FormatInt(evalContext.Rule.Id, 10)) @@ -103,9 +101,13 @@ func (this *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) err body, _ := bodyJSON.MarshalJSON() cmd := &m.SendWebhookSync{ - Url: opsgenieCreateAlertURL, + Url: opsgenieAlertURL, Body: string(body), HttpMethod: "POST", + HttpHeader: map[string]string{ + "Content-Type": "application/json", + "Authorization": fmt.Sprintf("GenieKey %s", this.ApiKey), + }, } if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { @@ -119,14 +121,17 @@ func (this *OpsGenieNotifier) closeAlert(evalContext *alerting.EvalContext) erro this.log.Info("Closing OpsGenie alert", "ruleId", evalContext.Rule.Id, "notification", this.Name) bodyJSON := simplejson.New() - bodyJSON.Set("apiKey", this.ApiKey) - bodyJSON.Set("alias", "alertId-"+strconv.FormatInt(evalContext.Rule.Id, 10)) + bodyJSON.Set("source", "Grafana") body, _ := bodyJSON.MarshalJSON() cmd := &m.SendWebhookSync{ - Url: opsgenieCloseAlertURL, + Url: fmt.Sprintf("%s/%s/close?identifierType=alias", opsgenieAlertURL,"alertId-"+strconv.FormatInt(evalContext.Rule.Id, 10)), Body: string(body), HttpMethod: "POST", + HttpHeader: map[string]string{ + "Content-Type": "application/json", + "Authorization": fmt.Sprintf("GenieKey %s", this.ApiKey), + }, } if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {