How to write not condition in alert manager route matches?

28 views
Skip to first unread message

Radha R4

unread,
Apr 29, 2020, 12:48:19 AM4/29/20
to Prometheus Users

How to write not condition in alert manager route matches? I want to execute this condition only when severity is not critical..

routes
    - match_re:
          severity: ^(?!critical)
      receiver: teams-channel-webhook-high-priority

I tried the above regex condition .But it didnt work.

I also tried with


not_match_re:

  severity: critical


Even that didnt work.

I want to match conditions when serverity is not critical.How to write this condition?

Brian Candler

unread,
Apr 29, 2020, 3:57:12 AM4/29/20
to Prometheus Users
You can make a nested tree of routes, which in effect gives you an "if ... then ... else ..." capability.

  routes:
    - ... something to do always
      continue: true
    - match:
        severity: critical
      routes:
        - ... things to do when critical
        - ...
    - ... things to do when not critical
    - ...

Leaving out the "match" condition entirely makes a rule match always.

Note that "continue: true" carries on to the next rule after a match, but only at the same level.  It will only fall out to the parent ruleset if no matches occur.

Or of course, you can explicitly match all non-critical severities e.g. match_re: severity: 'debug|informational|warning'

As to why what you wrote before didn't work:

1. The supported regex syntax for go's re2 library is defined here:

The (?!...) form is not implemented, due to the non-backtracking design of re2.

2. I don't know why you thought "not_match_re" would work, but it's not defined here:

I would have hoped that alertmanager would fail to start when given unknown config tag.  If it didn't, then that could be a bug.

Radha R4

unread,
Apr 29, 2020, 11:46:06 AM4/29/20
to Prometheus Users
Thankyou so much Brian for the details response...Its now clear to me :)
I was only testing using routing tree editor.and found it didnt work

Brian Candler

unread,
Apr 29, 2020, 12:17:50 PM4/29/20
to Prometheus Users
I didn't know about that tool - looks like it could be useful (if it works).

If you show what YAML you pasted into that, and what label set you tested with, maybe we can see what's wrong - either the tool or the YAML.

Reply all
Reply to author
Forward
0 new messages