I have a small question, in my discord alerts I have the title by default, the problem is that I don’t know if the title can be changed so that the dashboard link appears or if I can create a title to modify the title since it redirects me to url/alerting/list
Hey @victorcarretero, welcom to the forum!
I’ve never done that but I assume you can personalize your notification policies using template, with something like {{dashboardLink}}
.
Can you share your actual configuration?
{{ define "test-title" }}
{{ if gt (len .Alerts.Firing) 0 }}
🔥 {{ len .Alerts.Firing }} alert(s) firing
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
✅ {{ len .Alerts.Resolved }} alert(s) resolved
{{ end }}
{{ end }}
The problem is that if I click on the blue link it redirects me to /alerting/list and I don’t know if it is by default or I can change it somewhere.
What about:
:fire: {{ len .Alerts.Firing }} alert(s) firing on [Dashboard](your_dashboard_link)
The problem is not that it doesn’t change my name, but when I click on it, it still takes me to Grafana/alerting/test, and I want it to redirect me to another site, ideally to the dashboard where the alert was triggered. With your solution, the name of the Discord title has changed, but not where it redirects me.
I was kinda expecting that… Grafana build the title as text. For example it’s like clicking on a link on mail object (maybe it’s possible? but weird).
Can you share your body content? Or directly try the solution I provide on the body? Maybe with something like:
{{ define "test-body" }}
{{ if gt (len .Alerts.Firing) 0 }}
:fire: **Alerts Firing:**
{{ range .Alerts.Firing }}
- {{ .Labels.alertname }}: [Dashboard](your_dashboard_link)
{{ end }}
{{ end }}
{{ end }}
If it still don’t work, please share the result.
When I click I get this URL, not the URL that is written, this is where I want to change that URL, what the user sees is a bit indifferent, but when I click I want it to take me where I want.
Can you share your template? I wanna check something.
{{ define "test-body" }}
{{ if gt (len .Alerts.Firing) 0 }}
:fire:Preformatted text **Alerts Firing:**
{{ range .Alerts.Firing }}
- {{ .Labels.alertname }}: [Dashboard](https://grafana.com/)
{{ end }}
{{ end }}
{{ end }}
Ok, can you try to put the link of your dashboard and not only your grafana?
For example with this the link would be https://play.grafana.org/d/cdtmcc9n09bswa/benchmarks3a-dashboard-rendering
.
It’s the same, it changes to user view but when I click it redirects me to /alerting/list
I just saw that in your previous capture it show “Template: test-body” in the Title section…
Did you build the template message in the title section instead of the Message Content section? If so please try to edit your test-message…:
Title:
{{ define "test-title" }}
{{ if gt (len .Alerts.Firing) 0 }}
:fire: {{ len .Alerts.Firing }} alert(s) firing
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
:white_check_mark: {{ len .Alerts.Resolved }} alert(s) resolved
{{ end }}
{{ end }}
Message:
{{ define "test-body" }}
{{ if gt (len .Alerts.Firing) 0 }}
:fire: **Alerts Firing:**
{{ range .Alerts.Firing }}
- {{ .Labels.alertname }}: [Dashboard](your_dashboard_link)
{{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
:white_check_mark: **Alerts Resolved:**
{{ range .Alerts.Resolved }}
- {{ .Labels.alertname }}: [Dashboard](your_dashboard_link)
{{ end }}
{{ end }}
{{ end }}
In the screenshot there are both templates, but one is a message that the redirection does work, and the other is a title that the redirection does not work (The title would be the one in red). What I want is that when they click on the title it takes me to a URL, not to /alerting/list
I told you that I supposed that Grafana can’t redirected using the title… Why would it be problematic if only the body is doing the correct redirection? Because as a workarround, you can put the full link in title, then copy paste it…
Also, did you take a look at this topic?
If in the alerts that I have created in the message a URL field appears, but it is the message, and there are people who get used to clicking the title, so they can change it. I give you an example of one that I have created, which would be the message
{{ define "discord-kafka-down-controller" }}
{{ range .Alerts }}
**[{{ .Status|toUpper }}]** {{ .Labels.alertname }}
**Alert:** {{ .Labels.alertname}}
**Description:** Controller {{ .Labels.instance }} has been down for more than 5 minutes.
**Panel URL**: {{ .PanelURL }}
{{ .Annotations.Team }}
{{ end }}
{{ end }}
So your issue is about users seeing a link in title then clicking immediately before checking the message content?
Yes, they are not the smartest, that’s why I want to make the title redirect too
I mean, sometimes our works is alien things for “normal” people…
Would something like this do the trick?
Title
{{ define "test-title" }}
⚠️ **ATTENTION:** Do not click the title. See the correct link below!
{{ if gt (len .Alerts.Firing) 0 }}
:fire: {{ len .Alerts.Firing }} alert(s) firing
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
:white_check_mark: {{ len .Alerts.Resolved }} alert(s) resolved
{{ end }}
{{ end }}
Message, please note I made a line with full link and an other with you .PanelURL:
{{ define "test-body" }}
**IMPORTANT:**
The link below is the one you should use:
{{ if gt (len .Alerts.Firing) 0 }}
:fire: **Alerts Firing:**
{{ range .Alerts.Firing }}
- **Alert:** {{ .Labels.alertname }}
- **[CLICK HERE to View Dashboard]({{ .PanelURL }})**
- **[CLICK HERE to View Dashboard]**(your_dashboard_link)
{{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
:white_check_mark: **Alerts Resolved:**
{{ range .Alerts.Resolved }}
- **Alert:** {{ .Labels.alertname }}
- **[CLICK HERE to View Dashboard]({{ .PanelURL }})**
- **[CLICK HERE to View Dashboard]**(your_dashboard_link)
{{ end }}
{{ end }}
{{ end }}
Yes, it would be a solution, but I also wanted to know if it was possible to modify the link that is by default in the title so that in some alert I could also modify it.
Blockquote
By default, the title link typically redirects to the/alerting/list
page, which is a summary of all alerts. This behavior is built into Grafana
So you’d probably be able to change that in the Grafana conf, but I’m not sure about doing it it dynamically depending on the alert using templates.
Do you mean to change the displayed link or the link you get redirected to?