prometheus / alertmanager

Prometheus Alertmanager
https://prometheus.io
Apache License 2.0
6.57k stars 2.14k forks source link

Port number template functions from prometheus to alertmanager #3395

Open ashi009 opened 1 year ago

ashi009 commented 1 year ago

https://prometheus.io/docs/prometheus/latest/configuration/template_reference/#numbers are stateless, and pure functions, they could come in handy in alertmanager.

simonpasquier commented 1 year ago

Can you provide a use case? I fail to see where they would be useful in a notification template.

ashi009 commented 1 year ago

For our case, we have an alert for cert expiry, eg.

  - alert: CertificateNearExpiry
    expr: certificate_expiry_time - time() < 7 * 60*60*24
    annotations:
      expiry_time: ' {{ printf "certificate_expiry_time{sn=%q}" $labels.sn | query | first | value }}'
      expiry_time_humanreadable: ' {{ printf "certificate_expiry_time{sn=%q}" $labels.sn | query | first | value | humanizeTimestamp}}'
      value: !unsafe "{{ $value }}"
      value_humanreadable: !unsafe "{{ $value | humanizeDuration }}"

When this alert is routed to alertmanager, we have it delivered to both webhook and an email receiver. The former will take advantage of the raw value (for triggering automations), while the latter will use the humanreadable value for the template.

_humanreable annotations are only required because those number functions are not available in alertmanager world.

simonpasquier commented 1 year ago

alright this sounds like a niche but legit addition.