From 79dfb86c7b740ddd2f5d79ded49618dce541ce01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Freund?= Date: Fri, 19 Mar 2021 21:13:50 +0100 Subject: [PATCH 1/9] add the option to update message and description when sending alerts to opsgenie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Freund --- config/notifiers.go | 22 +++--- docs/configuration.md | 8 +++ notify/opsgenie/opsgenie.go | 120 ++++++++++++++++++++++++------- notify/opsgenie/opsgenie_test.go | 68 ++++++++++++++++-- 4 files changed, 175 insertions(+), 43 deletions(-) diff --git a/config/notifiers.go b/config/notifiers.go index 98eeddb4..27c02b88 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -455,16 +455,18 @@ type OpsGenieConfig struct { HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"` - APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"` - APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"` - Message string `yaml:"message,omitempty" json:"message,omitempty"` - Description string `yaml:"description,omitempty" json:"description,omitempty"` - Source string `yaml:"source,omitempty" json:"source,omitempty"` - Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"` - Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"` - Tags string `yaml:"tags,omitempty" json:"tags,omitempty"` - Note string `yaml:"note,omitempty" json:"note,omitempty"` - Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` + APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"` + APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"` + Message string `yaml:"message,omitempty" json:"message,omitempty"` + Description string `yaml:"description,omitempty" json:"description,omitempty"` + Source string `yaml:"source,omitempty" json:"source,omitempty"` + Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"` + Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"` + Tags string `yaml:"tags,omitempty" json:"tags,omitempty"` + Note string `yaml:"note,omitempty" json:"note,omitempty"` + Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` + UpdateMessage bool `yaml:"update_message,omitempty" json:"update_message,omitempty"` + UpdateDescription bool `yaml:"update_description,omitempty" json:"update_description,omitempty"` } const opsgenieValidTypesRe = `^(team|user|escalation|schedule)$` diff --git a/docs/configuration.md b/docs/configuration.md index 89e9fae7..3bdc56dd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -843,6 +843,14 @@ responders: # Priority level of alert. Possible values are P1, P2, P3, P4, and P5. [ priority: ] +# Whether or not to send a request to update alert message every time every time an alert is sent to OpsGenie +# By default, the message of the alert is never updated in OpsGenie, the new message only appears in activity log +[ update_message: | default = false ] + +# Whether or not to send a request to update alert description every time every time an alert is sent to OpsGenie +# By default, the description of the alert is never updated in OpsGenie +[ update_description: | default = false ] + # The HTTP client's configuration. [ http_config: | default = global.http_config ] ``` diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index 190ce275..c4fc7944 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -80,20 +80,34 @@ type opsGenieCloseMessage struct { Source string `json:"source"` } +type opsGenieUpdateMessageMessage struct { + Message string `json:"message,omitempty"` +} + +type opsGenieUpdateDescriptionMessage struct { + Description string `json:"description,omitempty"` +} + // Notify implements the Notifier interface. func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) { - req, retry, err := n.createRequest(ctx, as...) + requests, retry, err := n.createRequests(ctx, as...) if err != nil { return retry, err } - resp, err := n.client.Do(req) - if err != nil { - return true, err - } - defer notify.Drain(resp) + for _, req := range requests { + resp, err := n.client.Do(req) + if err != nil { + return true, err + } + defer notify.Drain(resp) - return n.retrier.Check(resp.StatusCode, resp.Body) + success, err := n.retrier.Check(resp.StatusCode, resp.Body) + if !success { + return false, err + } + } + return true, nil } // Like Split but filter out empty strings. @@ -109,7 +123,7 @@ func safeSplit(s string, sep string) []string { } // Create requests for a list of alerts. -func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http.Request, bool, error) { +func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*http.Request, bool, error) { key, err := notify.ExtractGroupKey(ctx) if err != nil { return nil, false, err @@ -130,26 +144,37 @@ func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http details[k] = tmpl(v) } + requests := []*http.Request{} + var ( - msg interface{} - apiURL = n.conf.APIURL.Copy() alias = key.Hash() alerts = types.Alerts(as...) ) switch alerts.Status() { case model.AlertResolved: - apiURL.Path += fmt.Sprintf("v2/alerts/%s/close", alias) - q := apiURL.Query() + resolvedEndpointURL := n.conf.APIURL.Copy() + resolvedEndpointURL.Path += fmt.Sprintf("v2/alerts/%s/close", alias) + q := resolvedEndpointURL.Query() q.Set("identifierType", "alias") - apiURL.RawQuery = q.Encode() - msg = &opsGenieCloseMessage{Source: tmpl(n.conf.Source)} + resolvedEndpointURL.RawQuery = q.Encode() + var msg = &opsGenieCloseMessage{Source: tmpl(n.conf.Source)} + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(msg); err != nil { + return nil, false, err + } + req, err := http.NewRequest("POST", resolvedEndpointURL.String(), &buf) + if err != nil { + return nil, true, err + } + requests = append(requests, req.WithContext(ctx)) default: message, truncated := notify.Truncate(tmpl(n.conf.Message), 130) if truncated { level.Debug(n.logger).Log("msg", "truncated message", "truncated_message", message, "alert", key) } - apiURL.Path += "v2/alerts" + createEndpointURL := n.conf.APIURL.Copy() + createEndpointURL.Path += "v2/alerts" var responders []opsGenieCreateMessageResponder for _, r := range n.conf.Responders { @@ -169,7 +194,7 @@ func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http responders = append(responders, responder) } - msg = &opsGenieCreateMessage{ + var msg = &opsGenieCreateMessage{ Alias: alias, Message: message, Description: tmpl(n.conf.Description), @@ -180,6 +205,55 @@ func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http Note: tmpl(n.conf.Note), Priority: tmpl(n.conf.Priority), } + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(msg); err != nil { + return nil, false, err + } + req, err := http.NewRequest("POST", createEndpointURL.String(), &buf) + if err != nil { + return nil, true, err + } + requests = append(requests, req.WithContext(ctx)) + + if n.conf.UpdateMessage { + updateMessageEndpointUrl := n.conf.APIURL.Copy() + updateMessageEndpointUrl.Path += fmt.Sprintf("v2/alerts/%s/message", alias) + q := updateMessageEndpointUrl.Query() + q.Set("identifierType", "alias") + updateMessageEndpointUrl.RawQuery = q.Encode() + updateMsgMsg := &opsGenieUpdateMessageMessage{ + Message: msg.Message, + } + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(updateMsgMsg); err != nil { + return nil, false, err + } + req, err := http.NewRequest("PUT", updateMessageEndpointUrl.String(), &buf) + if err != nil { + return nil, true, err + } + requests = append(requests, req) + } + + if n.conf.UpdateDescription { + updateDescriptionEndpointURL := n.conf.APIURL.Copy() + updateDescriptionEndpointURL.Path += fmt.Sprintf("v2/alerts/%s/description", alias) + q := updateDescriptionEndpointURL.Query() + q.Set("identifierType", "alias") + updateDescriptionEndpointURL.RawQuery = q.Encode() + updateDescMsg := &opsGenieUpdateDescriptionMessage{ + Description: msg.Description, + } + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(updateDescMsg); err != nil { + return nil, false, err + } + req, err := http.NewRequest("PUT", updateDescriptionEndpointURL.String(), &buf) + if err != nil { + return nil, true, err + } + requests = append(requests, req.WithContext(ctx)) + } } apiKey := tmpl(string(n.conf.APIKey)) @@ -188,16 +262,10 @@ func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http return nil, false, errors.Wrap(err, "templating error") } - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(msg); err != nil { - return nil, false, err + for _, req := range requests { + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", fmt.Sprintf("GenieKey %s", apiKey)) } - req, err := http.NewRequest("POST", apiURL.String(), &buf) - if err != nil { - return nil, true, err - } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", fmt.Sprintf("GenieKey %s", apiKey)) - return req.WithContext(ctx), true, nil + return requests, true, nil } diff --git a/notify/opsgenie/opsgenie_test.go b/notify/opsgenie/opsgenie_test.go index b2a96b12..6d9799ef 100644 --- a/notify/opsgenie/opsgenie_test.go +++ b/notify/opsgenie/opsgenie_test.go @@ -31,6 +31,9 @@ import ( "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/notify/test" "github.com/prometheus/alertmanager/types" + commoncfg "github.com/prometheus/common/config" + "github.com/prometheus/common/model" + "github.com/stretchr/testify/require" ) func TestOpsGenieRetry(t *testing.T) { @@ -167,12 +170,13 @@ func TestOpsGenie(t *testing.T) { }, } - req, retry, err := notifier.createRequest(ctx, alert1) + req, retry, err := notifier.createRequests(ctx, alert1) require.NoError(t, err) + require.Len(t, req, 1) require.Equal(t, true, retry) - require.Equal(t, expectedURL, req.URL) - require.Equal(t, "GenieKey http://am", req.Header.Get("Authorization")) - require.Equal(t, tc.expectedEmptyAlertBody, readBody(t, req)) + require.Equal(t, expectedURL, req[0].URL) + require.Equal(t, "GenieKey http://am", req[0].Header.Get("Authorization")) + require.Equal(t, tc.expectedEmptyAlertBody, readBody(t, req[0])) // Fully defined alert. alert2 := &types.Alert{ @@ -193,20 +197,70 @@ func TestOpsGenie(t *testing.T) { EndsAt: time.Now().Add(time.Hour), }, } - req, retry, err = notifier.createRequest(ctx, alert2) + req, retry, err = notifier.createRequests(ctx, alert2) require.NoError(t, err) require.Equal(t, true, retry) - require.Equal(t, tc.expectedBody, readBody(t, req)) + require.Len(t, req, 1) + require.Equal(t, tc.expectedBody, readBody(t, req[0])) // Broken API Key Template. tc.cfg.APIKey = "{{ kaput " - _, _, err = notifier.createRequest(ctx, alert2) + _, _, err = notifier.createRequests(ctx, alert2) require.Error(t, err) require.Equal(t, err.Error(), "templating error: template: :1: function \"kaput\" not defined") }) } } +func TestOpsGenieWithUpdate(t *testing.T) { + u, err := url.Parse("https://test-opsgenie-url") + require.NoError(t, err) + tmpl := test.CreateTmpl(t) + ctx := context.Background() + ctx = notify.WithGroupKey(ctx, "1") + opsGenieConfigWithUpdate := config.OpsGenieConfig{ + Message: `{{ .CommonLabels.Message }}`, + Description: `{{ .CommonLabels.Description }}`, + UpdateMessage: true, + UpdateDescription: true, + APIKey: "test-api-key", + APIURL: &config.URL{URL: u}, + HTTPConfig: &commoncfg.HTTPClientConfig{}, + } + notifierWithUpdate, err := New(&opsGenieConfigWithUpdate, tmpl, log.NewNopLogger()) + alert := &types.Alert{ + Alert: model.Alert{ + StartsAt: time.Now(), + EndsAt: time.Now().Add(time.Hour), + Labels: model.LabelSet{ + "Message": "new message", + "Description": "new description", + }, + }, + } + require.NoError(t, err) + requests, retry, err := notifierWithUpdate.createRequests(ctx, alert) + require.NoError(t, err) + require.True(t, retry) + require.Len(t, requests, 3) + + body0 := readBody(t, requests[0]) + body1 := readBody(t, requests[1]) + body2 := readBody(t, requests[2]) + key, _ := notify.ExtractGroupKey(ctx) + alias := key.Hash() + + require.Equal(t, requests[0].URL.String(), "https://test-opsgenie-url/v2/alerts") + require.NotEmpty(t, body0) + + require.Equal(t, requests[1].URL.String(), fmt.Sprintf("https://test-opsgenie-url/v2/alerts/%s/message?identifierType=alias", alias)) + require.Equal(t, body1, `{"message":"new message"} +`) + require.Equal(t, requests[2].URL.String(), fmt.Sprintf("https://test-opsgenie-url/v2/alerts/%s/description?identifierType=alias", alias)) + require.Equal(t, body2, `{"description":"new description"} +`) +} + func readBody(t *testing.T, r *http.Request) string { t.Helper() body, err := ioutil.ReadAll(r.Body) From adb69554a7a4f493e2790f0b1c81216d9d24e84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Freund?= Date: Fri, 19 Mar 2021 23:23:29 +0100 Subject: [PATCH 2/9] fix opsgenie retry handling logic error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Freund --- notify/opsgenie/opsgenie.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index c4fc7944..a6ba5b65 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -97,14 +97,13 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) for _, req := range requests { resp, err := n.client.Do(req) + notify.Drain(resp) if err != nil { return true, err } - defer notify.Drain(resp) - - success, err := n.retrier.Check(resp.StatusCode, resp.Body) - if !success { - return false, err + shouldRetry, err := n.retrier.Check(resp.StatusCode, resp.Body) + if err != nil { + return shouldRetry, err } } return true, nil From 09e755e1e55b26d59681b211509d75df361716a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Freund?= Date: Fri, 19 Mar 2021 23:46:54 +0100 Subject: [PATCH 3/9] fix response drain order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Freund --- notify/opsgenie/opsgenie.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index a6ba5b65..821a44b0 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -97,11 +97,11 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) for _, req := range requests { resp, err := n.client.Do(req) - notify.Drain(resp) if err != nil { return true, err } shouldRetry, err := n.retrier.Check(resp.StatusCode, resp.Body) + notify.Drain(resp) if err != nil { return shouldRetry, err } From e9f1f19611f19463f401167d963b9b75bab66c6e Mon Sep 17 00:00:00 2001 From: tomasfreund Date: Thu, 1 Jul 2021 18:12:08 +0200 Subject: [PATCH 4/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Julien Pivotto Signed-off-by: Tomáš Freund --- docs/configuration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 3bdc56dd..12bc2ed6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -843,8 +843,8 @@ responders: # Priority level of alert. Possible values are P1, P2, P3, P4, and P5. [ priority: ] -# Whether or not to send a request to update alert message every time every time an alert is sent to OpsGenie -# By default, the message of the alert is never updated in OpsGenie, the new message only appears in activity log +# Whether or not to send a request to update the alert message every time an alert is sent to OpsGenie +# By default, the message of the alert is never updated in OpsGenie, the new message only appears in activity log. [ update_message: | default = false ] # Whether or not to send a request to update alert description every time every time an alert is sent to OpsGenie From cafd84bedb3d8fa07379bee0afcb97d5316f2dce Mon Sep 17 00:00:00 2001 From: tomasfreund Date: Mon, 9 Aug 2021 13:23:45 +0200 Subject: [PATCH 5/9] Update docs/configuration.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Victor Coutellier Signed-off-by: Tomáš Freund --- docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 12bc2ed6..634dcee6 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -847,7 +847,7 @@ responders: # By default, the message of the alert is never updated in OpsGenie, the new message only appears in activity log. [ update_message: | default = false ] -# Whether or not to send a request to update alert description every time every time an alert is sent to OpsGenie +# Whether or not to send a request to update alert description every time an alert is sent to OpsGenie # By default, the description of the alert is never updated in OpsGenie [ update_description: | default = false ] From 6f071959b71d89262842e803b3984d9e3243dc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Freund?= Date: Tue, 10 Aug 2021 18:26:48 +0200 Subject: [PATCH 6/9] change update_message and update_description options to a single update_alerts option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Freund --- config/notifiers.go | 23 +++++++++++------------ notify/opsgenie/opsgenie.go | 19 +++++++++---------- notify/opsgenie/opsgenie_test.go | 13 ++++++------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/config/notifiers.go b/config/notifiers.go index 27c02b88..a00a9247 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -455,18 +455,17 @@ type OpsGenieConfig struct { HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"` - APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"` - APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"` - Message string `yaml:"message,omitempty" json:"message,omitempty"` - Description string `yaml:"description,omitempty" json:"description,omitempty"` - Source string `yaml:"source,omitempty" json:"source,omitempty"` - Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"` - Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"` - Tags string `yaml:"tags,omitempty" json:"tags,omitempty"` - Note string `yaml:"note,omitempty" json:"note,omitempty"` - Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` - UpdateMessage bool `yaml:"update_message,omitempty" json:"update_message,omitempty"` - UpdateDescription bool `yaml:"update_description,omitempty" json:"update_description,omitempty"` + APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"` + APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"` + Message string `yaml:"message,omitempty" json:"message,omitempty"` + Description string `yaml:"description,omitempty" json:"description,omitempty"` + Source string `yaml:"source,omitempty" json:"source,omitempty"` + Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"` + Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"` + Tags string `yaml:"tags,omitempty" json:"tags,omitempty"` + Note string `yaml:"note,omitempty" json:"note,omitempty"` + Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` + UpdateAlerts bool `yaml:"update_alerts,omitempty" json:"update_alerts,omitempty"` } const opsgenieValidTypesRe = `^(team|user|escalation|schedule)$` diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index 821a44b0..4a64ed65 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -214,7 +214,7 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h } requests = append(requests, req.WithContext(ctx)) - if n.conf.UpdateMessage { + if n.conf.UpdateAlerts { updateMessageEndpointUrl := n.conf.APIURL.Copy() updateMessageEndpointUrl.Path += fmt.Sprintf("v2/alerts/%s/message", alias) q := updateMessageEndpointUrl.Query() @@ -223,31 +223,30 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h updateMsgMsg := &opsGenieUpdateMessageMessage{ Message: msg.Message, } - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(updateMsgMsg); err != nil { + var updateMessageBuf bytes.Buffer + if err := json.NewEncoder(&updateMessageBuf).Encode(updateMsgMsg); err != nil { return nil, false, err } - req, err := http.NewRequest("PUT", updateMessageEndpointUrl.String(), &buf) + req, err := http.NewRequest("PUT", updateMessageEndpointUrl.String(), &updateMessageBuf) if err != nil { return nil, true, err } requests = append(requests, req) - } - if n.conf.UpdateDescription { updateDescriptionEndpointURL := n.conf.APIURL.Copy() updateDescriptionEndpointURL.Path += fmt.Sprintf("v2/alerts/%s/description", alias) - q := updateDescriptionEndpointURL.Query() + q = updateDescriptionEndpointURL.Query() q.Set("identifierType", "alias") updateDescriptionEndpointURL.RawQuery = q.Encode() updateDescMsg := &opsGenieUpdateDescriptionMessage{ Description: msg.Description, } - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(updateDescMsg); err != nil { + + var updateDescriptionBuf bytes.Buffer + if err := json.NewEncoder(&updateDescriptionBuf).Encode(updateDescMsg); err != nil { return nil, false, err } - req, err := http.NewRequest("PUT", updateDescriptionEndpointURL.String(), &buf) + req, err = http.NewRequest("PUT", updateDescriptionEndpointURL.String(), &updateDescriptionBuf) if err != nil { return nil, true, err } diff --git a/notify/opsgenie/opsgenie_test.go b/notify/opsgenie/opsgenie_test.go index 6d9799ef..cf47ec83 100644 --- a/notify/opsgenie/opsgenie_test.go +++ b/notify/opsgenie/opsgenie_test.go @@ -219,13 +219,12 @@ func TestOpsGenieWithUpdate(t *testing.T) { ctx := context.Background() ctx = notify.WithGroupKey(ctx, "1") opsGenieConfigWithUpdate := config.OpsGenieConfig{ - Message: `{{ .CommonLabels.Message }}`, - Description: `{{ .CommonLabels.Description }}`, - UpdateMessage: true, - UpdateDescription: true, - APIKey: "test-api-key", - APIURL: &config.URL{URL: u}, - HTTPConfig: &commoncfg.HTTPClientConfig{}, + Message: `{{ .CommonLabels.Message }}`, + Description: `{{ .CommonLabels.Description }}`, + UpdateAlerts: true, + APIKey: "test-api-key", + APIURL: &config.URL{URL: u}, + HTTPConfig: &commoncfg.HTTPClientConfig{}, } notifierWithUpdate, err := New(&opsGenieConfigWithUpdate, tmpl, log.NewNopLogger()) alert := &types.Alert{ From ecf87d15a0b1a8124772f0248c58b588452011d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Freund?= Date: Tue, 10 Aug 2021 18:31:58 +0200 Subject: [PATCH 7/9] add update_alerts option docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Freund --- docs/configuration.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 634dcee6..b1a97d36 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -843,13 +843,9 @@ responders: # Priority level of alert. Possible values are P1, P2, P3, P4, and P5. [ priority: ] -# Whether or not to send a request to update the alert message every time an alert is sent to OpsGenie -# By default, the message of the alert is never updated in OpsGenie, the new message only appears in activity log. -[ update_message: | default = false ] - -# Whether or not to send a request to update alert description every time an alert is sent to OpsGenie -# By default, the description of the alert is never updated in OpsGenie -[ update_description: | default = false ] +# Whether or not to update message and description of the alert in OpsGenie if it already exists +# By default, the alert is never updated in OpsGenie, the new message only appears in activity log. +[ update_alerts: | default = false ] # The HTTP client's configuration. [ http_config: | default = global.http_config ] From 92e7c4b1ea31b3c59e82010644633de9f47bb91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Freund?= Date: Tue, 10 Aug 2021 18:59:24 +0200 Subject: [PATCH 8/9] fix imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Freund --- notify/opsgenie/opsgenie_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/notify/opsgenie/opsgenie_test.go b/notify/opsgenie/opsgenie_test.go index cf47ec83..3066f5e3 100644 --- a/notify/opsgenie/opsgenie_test.go +++ b/notify/opsgenie/opsgenie_test.go @@ -23,10 +23,6 @@ import ( "time" "github.com/go-kit/log" - commoncfg "github.com/prometheus/common/config" - "github.com/prometheus/common/model" - "github.com/stretchr/testify/require" - "github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/notify/test" From 10e6e043764ac51349a813679b2728a32680cd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Freund?= Date: Tue, 10 Aug 2021 19:01:46 +0200 Subject: [PATCH 9/9] fix imports order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Freund --- notify/opsgenie/opsgenie_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/notify/opsgenie/opsgenie_test.go b/notify/opsgenie/opsgenie_test.go index 3066f5e3..543fc357 100644 --- a/notify/opsgenie/opsgenie_test.go +++ b/notify/opsgenie/opsgenie_test.go @@ -23,13 +23,14 @@ import ( "time" "github.com/go-kit/log" + commoncfg "github.com/prometheus/common/config" + "github.com/prometheus/common/model" + "github.com/stretchr/testify/require" + "github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/notify/test" "github.com/prometheus/alertmanager/types" - commoncfg "github.com/prometheus/common/config" - "github.com/prometheus/common/model" - "github.com/stretchr/testify/require" ) func TestOpsGenieRetry(t *testing.T) {