Prometheus Alerts.How to set a regular expression in the configuration?

56 Views Asked by At

I have configuration:

  config:
    global:
      resolve_timeout: 5m
    inhibit_rules:
    - equal:
      - namespace
      - alertname
      source_matchers:
      - severity = critical
      target_matchers:
      - severity =~ warning|info
    - equal:
      - namespace
      - alertname
      source_matchers:
      - severity = warning
      target_matchers:
      - severity = info
    - equal:
      - namespace
      source_matchers:
      - alertname = InfoInhibitor
      target_matchers:
      - severity = info
    receivers:
    - name: "null"
    - discord_configs:
      - webhook_url: https://discord.com/api/webhooks/xxxzUwDy
      name: discord
      - webhook_url: https://discord.com/api/webhooks/1197183190733963356/yyyyyy
      name: discord_infra
    route:
      group_by:
      - alertname
      group_interval: 5m
      group_wait: 1m
      receiver: discord
      repeat_interval: 15m
      routes:
      - match:
          alertname: NodeCPUHighUsage
        receiver: "discord_infra"
      - match:
          alertname: Watchdog
        receiver: "null"
      - match:
          alertname: KubeVersionMismatch
        receiver: "null"
      - match:
          alertname: KubeClientErrors
        receiver: "null"
      - group_interval: 5m
        group_wait: 1m
        match:
          severity: info
        receiver: discord
        repeat_interval: 15m
      - group_interval: 5m
        matchers: null

    templates:
    - '/etc/alertmanager/config/*.tmpl'

I need these alerts to be sent via discord_infra:

NodeFilesystemAlmostOutOfSpace
NodeFilesystemAlmostOutOfSpace
NodeFilesystemFilesFillingUp
NodeFilesystemFilesFillingUp
NodeFilesystemAlmostOutOfFiles
NodeFilesystemAlmostOutOfFiles
NodeNetworkReceiveErrs
NodeNetworkTransmitErrs
NodeHighNumberConntrackEntriesUsed
NodeTextFileCollectorScrapeError
NodeClockSkewDetected
NodeClockNotSynchronising
NodeRAIDDegraded
NodeRAIDDiskFailure
NodeFileDescriptorLimit
NodeFileDescriptorLimit
NodeCPUHighUsage
NodeSystemSaturation
NodeMemoryMajorPagesFaults
NodeMemoryHighUtilization
NodeDiskIOSaturation
NodeSystemdServiceFailed
NodeBondingDegraded
NodeNetworkInterfaceFlapping

I can use the construction for each name:

 - match:
     alertname: NodeFilesystemSpaceFillingUp
   receiver: "discord_infra"
 - match:
     alertname: NodeFilesystemSpaceFillingUp
   receiver: "discord_infra"
...

but I have a lot of alerts, so the configuration will be cumbersome.

Is it possible to apply a regular expression so that all alerts that start with Node will be sent by the receiver discord_infra?

Example:

 - match:
     alertname: '/Node*/gm'
   receiver: "discord_infra"
0

There are 0 best solutions below