Opsgenie webhook 422 error: Unprocessable Entity

Seeing the same 422 errors as described here:

I just want to be able to include the alert summary in the “message” field in my OpsGenie contact point. But it seems that that integration does not support templating in that field…?

image

image

I am currently on v9.5.2

For anyone who stumbles on this, it seems the problem was that the variable should be

{{ .CommonAnnotations.summary }}

(Other chats/docs suggested “Annotations” rather than “CommonAnnotations”. I’m guessing that is something that changed across version updates)

Update 2: nevermind. When I changed the message to use the “CommonAnnotations” format, that allowed me to test the contact point successfully, but when actual alerts fired, it still errored out. I think this is a Grafana bug.

Hi! :wave: It looks like you’re having trouble writing notification templates for OpsGenie. I should be able to help here :slight_smile:

I see a number of errors in the messages you have shared:

  1. While {{ .Annotations.summary }} is a valid Go template, there is no field called .Annotations at the start of the template. You either need to iterate over all of the alerts in the notification or, like you have attempted in your second message, print one of the common annotations shared between all alerts in the notification.

  2. Like above, {{ .CommonAnnotations.summary }} is a valid Go template, but it’s likely that each alert in the notification has different summaries, so summary is not a common annotation.

To answer the question about the 422 Unprocessable Content from OpsGenie, I’m guessing that when Grafana expands the templates {{ .Annotations.summary }} and {{ .CommonAnnotations.summary }} the result is an empty string, and looking at the Opsgenie docs the Message field is not allowed to be empty.

You can find more information on this in the docs Customize notifications.