Разрешение шаблонных полей в поле получателя оповещений Prometheus alertmanager

Я пытаюсь реализовать то, что здесь предложил Брайан Бразил:

https://www.robustperception.io/using-labels-to-direct-email-notifications/

Что я делаю, так это добавляю аннотацию пространства имен OpenShift к своим показателям, а затем получаю эту метку с помощью конфигурации Alertmanager. Но он, похоже, не работает и жалуется на то, что поле «to» пусто.

time="2018-06-26T13:28:48Z" level=debug msg="Notify attempt 1 for "email" failed: parsing to addresses: mail: no address" source="notify.go:585" 
time="2018-06-26T13:28:48Z" level=error msg="Error on notify: Cancelling notify retry for "email" due to unrecoverable error: parsing to addresses: mail: no address" source="notify.go:283" 
time="2018-06-26T13:28:48Z" level=error msg="Notify for 6 alerts failed: Cancelling notify retry for "email" due to unrecoverable error: parsing to addresses: mail: no address" source="dispatch.go:262" 

Вот некоторые из конфигураций, которые я пробовал:

  # default route if none match
  group_by: [annotation_contact_email]
  receiver: projectalerts

  group_by: []
  group_wait: 0s
  group_interval: 2s
  repeat_interval: 2s

receivers:
- name: alert-buffer-wh
  webhook_configs:
  - url: http://localhost:9099/topics/alerts 

- name: projectalerts
  email_configs:
  - to: '{{.GroupLabels.annotation_contact_email}}'

а также

  - name: projectalerts
      email_configs:
      - to: '{{.Labels.annotation_contact_email}}'

Он отлично работает со статически определенным электронным письмом.


person mojsha    schedule 26.06.2018    source источник
comment
Какое значение имеет метка annotation_contact_email?   -  person brian-brazil    schedule 26.06.2018
comment
Я получаю его с помощью этого запроса: сумма по (annotation_contact_email) (floor (увеличить (kube_pod_container_status_restarts_total [2h]) ›2) * на (пространство имен) group_left (annotation_contact_email) kube_namespace_annotations {annotation_contact_email) = ~. выглядит так: {[email protected]}   -  person mojsha    schedule 27.06.2018
comment
@ brian-brazil См. выше.   -  person mojsha    schedule 28.06.2018


Ответы (1)


Я наконец-то заработал, используя это:

global:

# The root route on which each incoming alert enters.
route:
  # default route if none match
  group_by: [annotation_contact_email]
  receiver: projectalerts

  # The labels by which incoming alerts are grouped together. For example,
  # multiple alerts coming in for cluster=A and alertname=LatencyHigh would
  # be batched into a single group.
  # TODO:
  #group_by: []
  group_wait: 0s
  group_interval: 5s
  repeat_interval: 3600s

  # All the above attributes are inherited by all child routes and can
  # overwritten on each.

receivers:
- name: alert-buffer-wh
  webhook_configs:
  - url: http://localhost:9099/topics/alerts

- name: projectalerts
  email_configs:
  - to: "{{ .GroupLabels.annotation_contact_email }}"
person mojsha    schedule 02.07.2018