No iteration just plain value of a key name I know.
This is how alert looks
What do I put in to template to so the notifications shows Hello or Hi?
No iteration just plain value of a key name I know.
This is how alert looks
What do I put in to template to so the notifications shows Hello or Hi?
In Slack? This should work:
{{ define "slack.body" }}
*Description*: {{ .Annotations.description }}
*Summary*: {{ .Annotations.summary }}
{{ end }}
Hi! You’ll need to iterate over the alerts before you can print the annotations as the data in notification templates is a list of alerts rather than a single alert. You can find more information in the documentation here Customize notifications | Grafana documentation.
Webhook for ntfy, but also tested email regularly
Unfortunately {{ .Annotations.summary }}
does not work. Tried adding value at the end too, tried under .alerts, tried playing with $
, tried commonAnnotations too… I think I spent few hours now on this but no luck.
With ntfy webhook the message send is raw, so I Actually see the json structure with the values.
But I seem to cant use anything from them. Not in template, not from contact point message and title input boxes. I either get blank or .
To test I mostly use TEST button in contact point, with custom filled summary, but also do test by actually forcing grafana alerts.
The values are there, I see them in json, I see them with default template, I just cant grab them and have them in message or title…
Ive seen those examples, I assumed they go that way because they are unsure about the range of data they could have, not as requirement for everything.
I also assumed that the dot in golang template serves as kinda an iterator of a current structure level without the need to write loops… but I will try to go this way some more.
Ok. figured it out. Funny how trivial things are once you know. This video was one where it finally clicked, but I could have noticed that dot sooner elsewhere.
So, what I did wrong is how I called the template in the contact point Message/Title section.
{{ template "test" }}
{{ template "test" . }}
The template itself:
{{ define "test" }}
{{ .CommonAnnotations.summary }}
{{ end }}
One can skip template and just write {{ .CommonAnnotations.summary }}
directly in to title or message of the contact point if thats all thats needed.
Iteration over alerts I tested too, plucking values out of arrays/lists with template like this:
{{ define "test" }}
{{ range .Alerts}}
{{ .Labels.whatever }}
{{ .Labels.alertname }}
{{ .Labels.instance }}
{{ .Annotations.summary }}
{{ end }}
{{ end }}
Capital letters required.