Grafana loki MS Teams (Grafana Version 10.4.1)


Hi community,
I am looking for assistance with setting up alerts in Grafana using loki as the datasource. My goal is to send alerts to MS Teams with the specified timestamp and message from my log line attached.
Alert Requirements:
Timestamp: Extract the timestamp from the log line.
Message: Extract the message from the log line (e.g., “NoLocation Collision detected for number +1234523330666…”).

I am using this template for my contact point
//
{{define “lokiToMsTeams” }}
{
“title”: “Error in {{.Fields.app }}({{.Fields.container }})”,
“summary”: “Error encountered running importer process”,
“sections”: [
{
“activityTitle”: “Error Details”,
“activitySubtitle”: “Error message”,
“facts”: [
{
“name”: “App”,
“value”: “{{.Fields.app }}”
},
{
“name”: “Container”,
“value”: “{{.Fields.container }}”
},
{
“name”: “Filename”,
“value”: “{{.Fields.filename }}”
},
{
“name”: “Job”,
“value”: “{{.Fields.job }}”
},
{
“name”: “Namespace”,
“value”: “{{.Fields.namespace }}”
},
{
“name”: “Node Name”,
“value”: “{{.Fields.node_name }}”
},
{
“name”: “Pod”,
“value”: “{{.Fields.pod }}”
},
{
“name”: “Stream”,
“value”: “{{.Fields.stream }}”
}
],
“text”: “{{.Line }}”
}
]
}
{{end }}
//
My alerts on Teams appear like below

Could someone guide me on how to configure this alerts to Teams with the specified timestamp and message from log line? Any examples or documentation references would be great appreciated,

Thank you in advance for your help

The template does not look correct. The field Fields does not exist in the template context. You can learn more in the documentation Create notification templates | Grafana documentation and Notification template reference | Prometheus

Also, the alerting is label-based, meaning that all information from the rule evaluation should be in labels. Also, it means that only metric queries to Loki are supported. To see what labels your query returns, click Preview button. It will return you a table with multiple rows (we call them dimensions), every row will have a list of labels and value. Those labels will be available in the template.

Thank you @yuriy.tseretyan for the great tips. I can now use labels to get my alert as envisioned.
How do I make the alert presentable, edit and remove these e and how do I add line breaks like
, they seems to get printed in my alerts

It is hard to tell what is going on in the screenshot. First, you need to determine how the alert looks like, where the data is, in annotations or in labels. Then write a template in the notification. You can find default templates here. Also, you can write templates in rule definition, annotations and labels support templating.

Thanks again @yuriy.tseretyan so this is how my alert rule looks like


Below are my labels and preview

My Contact Point message looks like this
image
Is there a reason my alerts don’t carry a timestamp as shown in the preview above?

Hi @yuriy.tseretyan Please help clarify this, I’ve been reading the documentation and trying different options with no luck