In Grafana cloud, using Loki, I want to send email alerts whenever I have the word “exception” in the logs, following my query:
rate({namespace="data", cluster="222111", job=~"data/airflow.*"} |~
(?i)exception [24h])
when running the query, this is the result I am getting:
In the email alert, I want to include these info, something like this:
So what I have done is, creating a template which would include all of these info as follows:
{{ define "logAlerts" }}
Labels:
alertname: {{ .Labels.rulename}}
Logs: {{ .Labels.Logs }}
grafana_folder: {{ .Labels.grafana_folder }}
exception: {{ .Labels.exception }}
date: {{ .Labels.date }}
time: {{ .Labels.time }}
cluster: {{ .Labels.cluster }}
container: {{ .Labels.container }}
filename: {{ .Labels.filename }}
job: {{ .Labels.job }}
namespace: {{ .Labels.namespace }}
node: {{ .Labels.node }}
pod: {{ .Labels.pod }}
service_name: {{ .Labels.service_name }}
stream: {{ .Labels.stream }}
{{ end }}
But I see that I’m not getting any of these data, only the following:
is there limitations in Loki to extract these data form the logs?
if not, how we can extract info from the log line?