Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpsGenie returns 422 when team is not specified #1223

Closed
iksaif opened this issue Feb 1, 2018 · 1 comment
Closed

OpsGenie returns 422 when team is not specified #1223

iksaif opened this issue Feb 1, 2018 · 1 comment

Comments

@iksaif
Copy link
Contributor

iksaif commented Feb 1, 2018

I'm still unsure if this is due to something on our side, but to help others users potentially affected by this I'm creating this issue.

Using the opsgenie notifier, we started to get the following error (with both 0.11.0 and 0.13.0).

{"message":"Request body is not processable. Please check the errors.","errors":{"teams[0]":"id or name should be provided"},"took":0.009,"requestId":"xxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

this happens because the query looks like:

{..."teams":[{"name":""}],...}

we made the following very quick and dirty patch to fix the issue

$ git diff
diff --git a/notify/impl.go b/notify/impl.go
index 7eddc3e..c519039 100644
--- a/notify/impl.go
+++ b/notify/impl.go
@@ -30,6 +30,7 @@ import (
        "net/url"
        "strings"
        "time"
+       "io/ioutil"
 
        "github.com/go-kit/kit/log"
        "github.com/go-kit/kit/log/level"
@@ -837,8 +838,13 @@ func (n *OpsGenie) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
                apiURL = n.conf.APIURL + "v2/alerts"
                var teams []map[string]string
                for _, t := range strings.Split(string(tmpl(n.conf.Teams)), ",") {
-                       teams = append(teams, map[string]string{"name": t})
+                       if len(t) != 0 {
+                               teams = append(teams, map[string]string{"name": t})
+                       }
                }
+               if len(teams) == 0 {
+                        teams = nil
+                }
                msg = &opsGenieCreateMessage{
                        Alias:       alias,
                        Message:     message,
@@ -859,6 +865,7 @@ func (n *OpsGenie) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
        if err := json.NewEncoder(&buf).Encode(msg); err != nil {
                return false, err
        }
+       fmt.Printf("JSON: %v\n", buf.String())
 
        req, err := http.NewRequest("POST", apiURL, &buf)
        if err != nil {
@@ -868,7 +875,12 @@ func (n *OpsGenie) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
        req.Header.Set("Authorization", fmt.Sprintf("GenieKey %s", n.conf.APIKey))
 
        resp, err := ctxhttp.Do(ctx, http.DefaultClient, req)
-
+       fmt.Printf("RESP: %v\n", resp)
+       if true {
+               body, _ := ioutil.ReadAll(resp.Body)
+               bodyString := string(body)
+               fmt.Printf("BODY: %v\n", bodyString)
+       }
        if err != nil {
                return true, err
        }
  • Team should be kept empty if no team are specified (probably true for some other fields)
  • A more detailed error than "opsgenie replied 422" should be printed when debug logs are on (probably true for all notifiers)
@iksaif
Copy link
Contributor Author

iksaif commented Feb 2, 2018

Seems to be similar to #1108 and #1107

iksaif pushed a commit to iksaif/alertmanager that referenced this issue Feb 5, 2018
See prometheus#1223, looks like OpsGenie now sometimes returns a 422 when you
don't specify a team. This change cleans up the JSON output and
add a few unit tests.
iksaif pushed a commit to iksaif/alertmanager that referenced this issue Feb 6, 2018
See prometheus#1223, looks like OpsGenie now sometimes returns a 422 when you
don't specify a team. This change cleans up the JSON output and
add a few unit tests.
iksaif pushed a commit to iksaif/alertmanager that referenced this issue Feb 6, 2018
See prometheus#1223, looks like OpsGenie now sometimes returns a 422 when you
don't specify a team. This change cleans up the JSON output and
add a few unit tests.
iksaif pushed a commit to iksaif/alertmanager that referenced this issue Feb 6, 2018
See prometheus#1223, looks like OpsGenie now sometimes returns a 422 when you
don't specify a team. This change cleans up the JSON output and
add a few unit tests.
stuartnelson3 pushed a commit that referenced this issue Feb 6, 2018
See #1223, looks like OpsGenie now sometimes returns a 422 when you
don't specify a team. This change cleans up the JSON output and
add a few unit tests.
@iksaif iksaif closed this as completed Apr 5, 2018
hh pushed a commit to ii/alertmanager that referenced this issue Jan 5, 2019
This makes it consistent with other networking metrics like node_network_receive_bytes_total

This closes prometheus#1223
hh pushed a commit to ii/alertmanager that referenced this issue Feb 8, 2019
* Rename interface to device in netclass collector

This makes it consistent with other networking metrics like node_network_receive_bytes_total

This closes prometheus#1223 

Signed-off-by: Johannes 'fish' Ziemke <github@freigeist.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant