Grafana Alerts: How to add alert created time (startsAt) into alert template?

Is it possible to add the alert created time (a.k.a. startsAt) into the alert template? I tried to use {{ .StartsAt }} to solve it, but it seems it didn’t work.

At slack, the Alerting time didn’t show.
Is it possible to add alert created time (startsAt) into alert template?

Best regards,

Hi @heehee850523 , Yes, you can add the {{ .StartsAt }} but maybe the problem is the context where you are trying to get this value in the template.
Have you tried to preview this template and see what is the error returned by the preview response?

1 Like

@soniaaguilar First of all, thank you very much for your response. I am a bit confused about the context of ‘the problem is the context’.As I am new to Grafana, I still find it a bit challenging to navigate through the operations. After adding/editing a template, how can I preview the template?

You’re welcome, @heehee850523 , here you have some explanation about how you can preview templates : Create notification templates | Grafana documentation.

Hi Chris! :wave:

The issue is where you have {{ .StartsAt }}, . does not refer to an alert, but a top-level structure called ExtendedData.

You can see from the reference that ExtendedData contains a list of alerts. This is because Alertmanager notifications work on groups of alerts, not individual alerts.

If you want to print the StartsAt time of each alert in the notification you’ll want to iterate over all alerts in the notification using range as shown here.