alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

OpsGenie integration broken in 0.6.0

Open Nonymus opened this issue 9 years ago • 1 comments

When notifying opsgenie in 0.6.0, it looks like alertmanager doesn't generate valid json for the alias field anymore. See the comparison of requests captured with nc below:

v0.6.0:

POST /v1/json/alert HTTP/1.1 
Host: jposchma-dt2.lcs.intern:9090
User-Agent: Go-http-client/1.1
Content-Length: 433
Content-Type: application/json
Accept-Encoding: gzip

{"apiKey":"<redacted>","alias":"9Ԏ/\ufffd\ufffdY;ek\ufffd9\ufffd\ufffd\ufffd?    \u001e\ufffdy\ufffd\ufffdi9\u0014\ufffd\ufffd\u0011\"\ufffdC\ufffd\ufffd","message":"[FIRING:1]     TestAlert1 (page)","description":"\nAlerts Firing:\nLabels:\n - alertname = TestAlert1\n - severity = page\nAnnotations:\nSource: \n\n","details":{},"source":"http://79e37143360f:9093/#/alerts?receiver=ops-pager","teams":"ops_team"}

Notice the unicode characters and additional quotes.

v0.5.1 works fine:

POST /v1/json/alert HTTP/1.1
Host: jposchma-dt2.lcs.intern:9090
User-Agent: Go-http-client/1.1
Content-Length: 331
Content-Type: application/json
Accept-Encoding: gzip

{"apiKey":"<redacted>","alias":986256492683236487,"message":"[FIRING:1] TestAlert1 (page)","description":"\nAlerts Firing:\nLabels:\n - alertname = TestAlert1\n - severity = page\nAnnotations:\nSource: \n\n","details":{},"source":"http://9ec58373bc61:9093/#/alerts?receiver=ops-pager","teams":"ops_team"}

This leads to alerts not being shown in OpsGenie for the most part. Sometimes they do, with an unreadable alias.

Nonymus avatar Apr 27 '17 09:04 Nonymus

I shifted several integrations to use strings instead of numbers for deduplication fields like the alias. For OpsGenie, we are doing a hash regardless as it has a 512 character limitation: https://www.opsgenie.com/docs/web-api/alert-api#createAlertRequest I also used the hash to not risk hitting similar (undocumented) restrictions with other services.

Mistake here was to not properly hex encode the hash byte slice but directly converting it to a string. If OpsGenie checked the string for valid unicode characters I would understand alerts being rejected. But some passing with invalid characters and some being rejected is certainly odd behavior.

fabxc avatar Apr 27 '17 11:04 fabxc