【问题标题】:Add slack fields to Prometheus alert manager slack notifications将 slack 字段添加到 Prometheus 警报管理器 slack 通知
【发布时间】:2019-02-12 03:01:04
【问题描述】:

新版 Prometheus 警报管理器增加了对 slack 附件中fields 部分的支持。我正在尝试设置一个go template 来循环生成每个警报标签的字段。测试配置后,我收到语法错误“无法读取隐式映射对;缺少冒号”。有没有人尝试过同样的事情并成功了?非常感谢。我的配置如下:

global:
  resolve_timeout: 5m
templates:
- '/etc/alertmanager/template/*.tmpl'
route:
  # All alerts in a notification have the same value for these labels.
  group_by: ['alertname', 'instance', 'pod']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  receiver: 'slack-test'
  routes:
  # Go spam channel
  - match:
      alertname: DeadMansSwitch
    receiver: 'null'
- name: 'slack-test'
  slack_configs:
  - channel: '#alert'
    api_url: 'https://hooks.slack.com/services/XXXXX/XXXX/XXXX'
    username: 'Prometheus Event Notification'
    color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
    title: '[`{{ .Labels.severity }}`] Server alert'
    text: |-
      {{ range .Alerts }}
        {{ .Annotations.message }}
      {{ end }}
    short_fields: true
    fields:
    {{ range .Labels.SortedPairs }}
      title:{{ .Name }}
      value:`{{ .Value }}`
    {{ end }}
    send_resolved: true
  #email_configs:
  #- to: 'your_alert_email_address'
  #  send_resolved: true
- name: 'null'

试过这个也不行。

    fields:
    {{ range .Labels.SortedPairs }}
     - title: {{ .Name }}
       value: `{{ .Value }}`
    {{ end }}

【问题讨论】:

    标签: slack prometheus prometheus-alertmanager


    【解决方案1】:

    问题是您在配置文件中使用了 go 模板,但 prometheus 仅支持 config values 中的 go 模板。 Title 和 Value 都是“tmpl_string”类型,这意味着它们是一个字符串,它是一个 go 模板。 https://prometheus.io/docs/alerting/configuration/#field_config

    正确

     fields:
       title: '{{ if (true) }}inside the title VALUE{{ end }}'
       value: 'foo'
    

    不正确

     fields:
       {{ if (true) }}outside the config values
       title: 'inside the title VALUE'
       value: 'foo'
      {{ end }}
    

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 2021-11-25
      • 1970-01-01
      • 2021-12-23
      相关资源
      最近更新 更多