prometheus 在警报注释中使用 html 内容并在电子邮件模板中使用它 [英] prometheus using html content in alerts annotations and using it in email template

查看:137
本文介绍了prometheus 在警报注释中使用 html 内容并在电子邮件模板中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们的警报看起来像

So our alert looks like

ALERT alert_name
   condition
   FOR 30s
   LABELS {some labels}
   ANNOTATIONS {
       header = "<b> data is {{ $labels.label_name }} </b>"
   }

电子邮件模板看起来像.

email template looks like.

{{ define "our_default_template" }}
{{range .Alerts}}
{{ .Annotations.header }}
{{ end }}
{{ end }}

alertmanager.yml 看起来像

alertmanager.yml looks like

receivers:
- name: 'email-sender'
  email_configs:
  - to: "email address"
    send_resolved: true
    html: '{{ template "our_default_template" . }}'

templates:
- '<path to templates>/*tmpl'

我们收到电子邮件,但内容不正确.

We are getting emails but content is not right.

我们收到的邮件内容:

<代码>数据是标签值

我们想要的:

数据是label_value

所以我们想要的是 html 输出.

So what we want is html output.

有人可以帮忙吗?

推荐答案

首先,我建议不要在 Prometheus 端做 HTML,因为随着系统的发展,这可能会导致维护问题.

Firstly I'd recommend against doing HTML on the Prometheus end, as that may cause maintenance issues as your system evolves.

看起来 Go 对 HTML 的自动转义就是这里发生的事情,因此您需要一种方法来告诉 Go 的模板语言这是安全的.alertmanager 没有这个功能(Prometheus 有),所以我提交了 https://github.com/prometheus/alertmanager/issues/314 用于此.

It looks like Go's auto-escaping of HTML is what's happening here, so you need a way to tell Go's templating language that that's safe. The alertmanager doesn't have that function (Prometheus does), so I've filed https://github.com/prometheus/alertmanager/issues/314 for this.

一旦修复,您就可以执行 {{ .Annotations.header |safeHtml }}

Once that's fixed you'll be able to do {{ .Annotations.header | safeHtml }}

这篇关于prometheus 在警报注释中使用 html 内容并在电子邮件模板中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆