Grafana Alert Notification Template - How to change timezone to UTC+08

Hello Grafana Community,

I am working on customizing the alert notification template in Grafana and need assistance with changing the timezone to UTC+08. Currently, my template looks like this:

{{ define "alert.print_alert" -}}

 {{ .Labels.alertname }}
Time: {{ .StartsAt.Format "2006-01-02 03:04:05 MST" }}
{{ end }}

Grafana Version: Grafana v10.2.0

I would like to adjust the timezone to UTC+08. Can someone guide me on the correct syntax or configuration to achieve this?

Thank you in advance for your help!

2 Likes

I would also like to hear an answer to this. The dashboard shows my local time, but alerts are always in UTC. Where can I change the setting for this?

1 Like

Also struggling with the correct syntax. Gos time package documentation referenced in grafana docs is not providing much help

2 Likes

Struggling with this too. Did you get a solution for this?

No solution has been presented as yet. We do include timestamps in UTC on our notifications but they are confusing to calculate at a glance. Is there something I’m missing?

You aren’t using Grafana OnCall as your alert manager, are you? I finally figured out how to do it within OnCall’s templating system (Jinja2/Python), which I will explain below. However, I haven’t yet figured out how to do this within Grafana’s templating system (Go template/text) - sorry.

For OnCall templates, you can use the datetimeformat_as_timezone filter.
As an example:
{{ payload.alerts[0].startsAt | iso8601_to_time | datetimeformat_as_timezone('%I:%M %p on %a, %B %d %Z','US/Eastern') }}

Hello! :wave: We just added this feature to Alertmanager (Add date and tz functions to templates by grobinson-grafana · Pull Request #3812 · prometheus/alertmanager · GitHub). We’ll work to add it to Grafana and you should expect it in the next release.