php Xiaobian Yuzai will introduce you how to obtain the host name in the subject of the Grafana 9.0 alert email. Grafana is a powerful open source monitoring and visualization tool that can send email notifications when problems occur by setting alert rules. However, sometimes the host name in the email subject may be the key information we need. This article will explain in detail how to obtain this information to help you better monitor and troubleshoot.
I try to use alert email template in grafana 9.0.
I got the hostname of the alert host in the alert email by adding {{ $values.b0.labels.host }}
to the alert rule summary. If I don't use any template it works fine.
However, I am using a template as the subject of the alert email and need to access the hostname in the template.
My template looks like this:
{{ define "xxx.email.subject" }} {{ if .Alerts.Firing -}}[{{toUpper .Status}}:{{ len .Alerts.Firing }}] {{ .CommonLabels.alertname }} {{ end }} {{ if .Alerts.Resolved -}}[{{ .Status}}:{{ len .Alerts.Resolved }}] {{ end }} {{ end }}
I tried adding {{ .commonlabels.hostname }}
and other different keywords with no success.
Can someone tell me how to access the hostname directly in the template?
greeting.
The problem is that my alarm is not connected to the panel correctly.
If you connect alerts with a panel, you can access the host labels using {{ .CommonLabels.host }}
. Of course, you should have a setup with a defined tag.
The above is the detailed content of How to get the hostname in the subject of Grafana 9.0 alert emails?. For more information, please follow other related articles on the PHP Chinese website!