operator icon indicating copy to clipboard operation
operator copied to clipboard

vmalert: add template variable to hold the "for:" alert rule value

Open rcowham opened this issue 1 year ago • 2 comments

It would be nice to be able to include

  - alert: InstanceDown
    expr: up == 0
    for: 5m
    labels:
      severity: page
    annotations:
      description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.'
      summary: 'Instance {{ $labels.instance }} down'

E.g. allow something like this:

      description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than {{ $for }}.'

Thoughts?

rcowham avatar Jun 26 '24 15:06 rcowham

Hello, it should be already possible to use the value of for field from alerting rule, in this case it should be 5m.

For the actual firing state of alert, it's recommended to use value of StartsAt field at alertmanager

https://prometheus.io/docs/alerting/latest/notifications/#alert

f41gh7 avatar Jun 26 '24 20:06 f41gh7

Apologies - but at the link you gave I am not seeing "for" as an option. Should I raise it with prometheus guys?

rcowham avatar Jul 04 '24 14:07 rcowham

hey @rcowham $for is available as template variable please check a list of variables here https://docs.victoriametrics.com/victoriametrics/vmalert/#templating

AndrewChubatiuk avatar Jul 07 '25 06:07 AndrewChubatiuk