Hi All,
I’m trying a alerting template to get alert notified in to a slack channel. Integrations and everything works fine. I need to optimize the alerting template so that it has only needed information in it.
Current situation is that when I get the alert, apart from the details I have mentioned in the alerting template, at the end it provides all the labels and a annotations section with number of links(source URL, dashboard URL, Panel URL etc).
How can I get rid of these URLs and the labels and only notify from the details I have defined?
For example below is my alert template,
{{ define "custom_message" -}}
{{ range .Alerts }}
The name of the alert is {{ .Labels.alertname }}
{{ end }}
{{ end }}
How can I only get the things in this template without any other information?
Thank you in advance
hi @sanjayastn
Is that template working for you? If not, can you share a screenshot of the message you are receiving ?
What version of Grafana are you using an on what platform (Cloud, Docker, binary, etc)
I assume that you have referenced this template in the contact point settings. For example, this is how I reference my own custom template in the Optional [email] settings
Hi @antonio,
Thank you for the reply.
My account is in Grafana cloud (free version with Grafana Cloud (steady)). Below is the template I use,
{{ define "custom.test_slack" -}}
{{ if .Alerts.Firing -}}
🔥[{{ .Status | toUpper }}:{{ len .Alerts }}] {{ range .Alerts -}}{{ .Labels.alertname }}
{{ template "alerts.test.details" . }}
{{- end }}
{{- end }}
{{ end -}}
{{ define "alerts.test.details" }}
{{ end -}}
and yes I have referenced this template in the contact points.
Below is a sample alert I get in to slack,
I get all the labels, annotations and other stuff. Not sure why these are getting removed.
Thanks @sanjayastn
I can reproduce this issue on Cloud
Plus I get some errors when selecting the template from the contact point.
GET
https://grafana.net/api/alertmanager/grafana/config/api/v1/receivers
failed to retrieve receivers: Response content-type is not application/json: text/plain; charset=utf-8
However, if using Grafana v12.0.0 (4c0e7045f9)
locally, the template works
I will internally consult the team. In the meantime, it would be great if you could open an issue in our repo for visibility. Or I can do it for you of course.
1 Like
Never mind, I eventually got the notification to work using your template:
{{ define "custom.test_slack" -}}
{{ if .Alerts.Firing -}}
🔥[{{ .Status | toUpper }}:{{ len .Alerts }}] {{ range .Alerts -}}{{ .Labels.alertname }}
{{ template "alerts.test.details" . }}
{{- end }}
{{- end }}
{{ end -}}
{{ define "alerts.test.details" }}
{{ end -}}
I will still check if there are any known issues and I’ll get back to you
1 Like
@sanjayastn
I haven’t found any recent related issues.
If the problem persists on your end, please do open an issue (see link above), document the exact reproduction steps, errors, and reference this post. Thank you/
1 Like
Hi @antonio ,
Many thanks for checking on this, apologies for not replying earlier.
I have tried with your template as well, but it still provides me all the labels in the slack alert. Not sure what it is, did you do anything specific? or just created the template and added it to the contact point?
Also, I’m using a slack webhook to send the notifications to the channel