Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Prometheus 普罗米修斯在警报注释中使用html内容,并在电子邮件模板中使用它_Prometheus - Fatal编程技术网

Prometheus 普罗米修斯在警报注释中使用html内容,并在电子邮件模板中使用它

Prometheus 普罗米修斯在警报注释中使用html内容,并在电子邮件模板中使用它,prometheus,Prometheus,所以我们的警报看起来像 ALERT alert_name condition FOR 30s LABELS {some labels} ANNOTATIONS { header = "<b> data is {{ $labels.label_name }} </b>" } alertmanager.yml看起来像 receivers: - name: 'email-sender' email_configs: - to

所以我们的警报看起来像

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

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

templates:
- '<path to templates>/*tmpl'
接收器:
-名称:“电子邮件发件人”
电子邮件\u配置:
-收件人:“电子邮件地址”
发送解决方案:正确
html:“{template”我们的默认模板“}”
模板:
-“/*tmpl”
我们收到电子邮件,但内容不对

我们收到的邮件:

数据是标签值

我们想要的是:

数据是标签U值

所以我们想要的是html输出


有人能帮忙吗?

首先,我建议不要在Prometheus端使用HTML,因为这可能会在系统发展过程中导致维护问题

看起来Go的HTML自动转义就是这里发生的事情,所以您需要一种方法来告诉Go的模板语言这是安全的。alertmanager没有这个功能(普罗米修斯有),所以我申请了这个


修复后,您将能够执行
{{.Annotations.header | safeHtml}}

谢谢@brian brazil曾尝试过safeHtml,但遇到了未知函数之类的错误。请确保您是从头开始运行的。这一变化尚未发布。
receivers:
- name: 'email-sender'
  email_configs:
  - to: "email address"
    send_resolved: true
    html: '{{ template "our_default_template" . }}'

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