配置

Alertmanager  是透過命令列引數和配置檔案進行配置的。命令列引數用於配置不可變的系統引數,而配置檔案則定義了抑制規則、通知路由和通知接收器。

視覺化編輯器 可以輔助構建路由樹。

要檢視所有可用的命令列引數,請執行 alertmanager -h

Alertmanager 可以在執行時重新載入其配置。如果新配置的格式不正確,則不會應用更改,並且會記錄錯誤。透過向程序傳送 SIGHUP 訊號或向 /-/reload 端點發送 HTTP POST 請求,可以觸發配置重新載入。

限制

Alertmanager 支援透過命令列引數配置一些限制。

要限制靜默(包括已過期的靜默)的最大數量,請使用 --silences.max-silences 引數。您可以使用 --silences.max-silence-size-bytes 限制單個靜默的最大大小,單位為位元組。

這兩個限制預設均未啟用。

配置檔案介紹

要指定載入哪個配置檔案,請使用 --config.file 引數。

./alertmanager --config.file=alertmanager.yml

該檔案採用 YAML 格式  編寫,由下方描述的模式定義。括號表示引數是可選的。對於非列表引數,其值將被設定為指定的預設值。

通用佔位符定義如下

  • <duration>:匹配正則表示式 ((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0) 的時間段,例如 1d1h30m5m10s
  • <labelname>:匹配正則表示式 [a-zA-Z_][a-zA-Z0-9_]* 的字串
  • <labelvalue>:Unicode 字元組成的字串
  • <filepath>:當前工作目錄中的有效路徑
  • <boolean>: 一個布林值,可取 truefalse
  • <string>: 一個普通字串
  • <secret>: 一個普通字串,是秘密資訊,如密碼
  • <tmpl_string>:在使用前進行模板展開的字串
  • <tmpl_secret>:在使用前進行模板展開的敏感字串(密碼/金鑰)
  • <int>:整數值
  • <regex>:任何有效的 RE2 正則表示式 (該正則表示式在兩端都是錨定的。要取消錨定,請使用 .*<regex>.*。)

其他佔位符另行說明。

提供的有效示例檔案 展示了其具體用法。

檔案佈局和全域性設定

全域性配置指定了在所有其他配置上下文中均有效的引數。它們也用作其他配置部分的預設值。本頁下方記錄了其他頂級部分。

global:
  # The default SMTP From header field.
  [ smtp_from: <tmpl_string> ]
  # The default SMTP smarthost used for sending emails, including port number.
  # Port number usually is 25, or 587 for SMTP over TLS (sometimes referred to as STARTTLS).
  # Example: smtp.example.org:587
  [ smtp_smarthost: <string> ]
  # The default hostname to identify to the SMTP server.
  [ smtp_hello: <string> | default = "localhost" ]
  # SMTP Auth using CRAM-MD5, LOGIN and PLAIN. If empty, Alertmanager doesn't authenticate to the SMTP server.
  # PLAIN is only supported when using TLS.
  [ smtp_auth_username: <string> ]
  # SMTP Auth using LOGIN and PLAIN.
  [ smtp_auth_password: <secret> ]
  # SMTP Auth using LOGIN and PLAIN.
  [ smtp_auth_password_file: <string> ]
  # SMTP Auth using PLAIN.
  [ smtp_auth_identity: <string> ]
  # SMTP Auth using CRAM-MD5.
  [ smtp_auth_secret: <secret> ]
  # SMTP Auth using CRAM-MD5.
  [ smtp_auth_secret_file: <string> ]
  # The default SMTP TLS requirement.
  # Note that Go does not support unencrypted connections to remote SMTP endpoints.
  [ smtp_require_tls: <bool> | default = true ]
  # The default TLS configuration for SMTP receivers
  [ smtp_tls_config: <tls_config> ]
  # Force implicit TLS regardless of SMTP port
  [ smtp_force_implicit_tls: <bool>]

  # Default settings for the JIRA integration.
  [ jira_api_url: <string> ]

  # The API URL to use for Slack notifications.
  [ slack_api_url: <secret> ]
  [ slack_api_url_file: <filepath> ]
  [ slack_app_token: <secret> ]
  [ slack_app_token_file: <filepath> ]
  [ slack_app_url: <string> ]

  [ victorops_api_key: <secret> ]
  [ victorops_api_key_file: <filepath> ]
  [ victorops_api_url: <string> | default = "https://alert.victorops.com/integrations/generic/20131114/alert/" ]
  [ pagerduty_url: <string> | default = "https://events.pagerduty.com/v2/enqueue" ]
  [ opsgenie_api_key: <secret> ]
  [ opsgenie_api_key_file: <filepath> ]
  [ opsgenie_api_url: <string> | default = "https://api.opsgenie.com/" ]
  [ rocketchat_api_url: <string> | default = "https://open.rocket.chat/" ]
  [ rocketchat_token: <secret> ]
  [ rocketchat_token_file: <filepath> ]
  [ rocketchat_token_id: <secret> ]
  [ rocketchat_token_id_file: <filepath> ]
  [ wechat_api_url: <string> | default = "https://qyapi.weixin.qq.com/cgi-bin/" ]
  [ wechat_api_secret: <secret> ]
  [ wechat_api_secret_file: <string> ]
  [ wechat_api_corp_id: <string> ]
  [ telegram_api_url: <string> | default = "https://api.telegram.org" ]
  # The default Telegram bot token. It is mutually exclusive with `telegram_bot_token_file`.
  [ telegram_bot_token: <secret> ]
  # The default configuration to read the Telegram bot token from a file. It is mutually exclusive with `telegram_bot_token`.
  [ telegram_bot_token_file: <string> ]
  [ webex_api_url: <string> | default = "https://webexapis.com/v1/messages" ]
  [ mattermost_webhook_url: <secret> ]
  [ mattermost_webhook_url_file: <string> ]
  # The default HTTP client configuration
  [ http_config: <http_config> ]

  # ResolveTimeout is the default value used by alertmanager if the alert does
  # not include EndsAt, after this time passes it can declare the alert as resolved if it has not been updated.
  # This has no impact on alerts from Prometheus, as they always include EndsAt.
  [ resolve_timeout: <duration> | default = 5m ]

# Files from which custom notification template definitions are read.
# The last component may use a wildcard matcher, e.g. 'templates/*.tmpl'.
templates:
  [ - <filepath> ... ]

# The root node of the routing tree.
route: <route>

# A list of notification receivers.
receivers:
  - <receiver> ...

# A list of inhibition rules.
inhibit_rules:
  [ - <inhibit_rule> ... ]

# DEPRECATED: use time_intervals below.
# A list of mute time intervals for muting routes.
mute_time_intervals:
  [ - <time_interval> ... ]

# A list of time intervals for muting/activating routes.
time_intervals:
  [ - <time_interval> ... ]

# Optional event recorder configuration.  Captures significant
# Alertmanager events (startup/shutdown, alert lifecycle, silences,
# notifications) and ships them to one or more outputs (file, webhook,
# kafka).  Recording is gated behind the `event-recorder` feature flag;
# pass `--enable-feature=event-recorder` on the command line to
# activate it.  See the Event Recorder section below.
[ event_recorder: <event_recorder_config> ]

路由相關設定允許配置如何根據時間對告警進行路由、聚合、限流和靜默。

<route>

route(路由)塊定義了路由樹中的一個節點及其子節點。如果未設定,其可選的配置引數將繼承自其父節點。

每條告警都會從配置的頂級路由進入路由樹,頂級路由必須匹配所有告警(即不配置任何匹配器)。然後,它會遍歷子節點。如果 continue 設定為 false,它會在匹配到第一個子節點後停止。如果匹配節點上的 continue 為 true,告警將繼續與後續的兄弟節點進行匹配。如果告警不匹配某節點的任何子節點(沒有匹配的子節點,或者子節點不存在),則該告警將根據當前節點的配置引數進行處理。

有關分組的更多資訊,請參閱 Alertmanager 概念

[ receiver: <string> ]
# 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.
#
# To aggregate by all possible labels use the special value '...' as the sole label name, for example:
# group_by: ['...']
# This effectively disables aggregation entirely, passing through all
# alerts as-is. This is unlikely to be what you want, unless you have
# a very low alert volume or your upstream notification system performs
# its own grouping.
[ group_by: '[' <labelname>, ... ']' ]

# Whether an alert should continue matching subsequent sibling nodes.
[ continue: <boolean> | default = false ]

# DEPRECATED: Use matchers below.
# A set of equality matchers an alert has to fulfill to match the node.
match:
  [ <labelname>: <labelvalue>, ... ]

# DEPRECATED: Use matchers below.
# A set of regex-matchers an alert has to fulfill to match the node.
match_re:
  [ <labelname>: <regex>, ... ]

# A list of matchers that an alert has to fulfill to match the node.
matchers:
  [ - <matcher> ... ]

# How long to wait before sending the first notification for a new group of
# alerts. Allows to wait for alerts to arrive from other rule groups or
# Prometheus servers, and for one or more inhibiting alerts to arrive and mute
# any target alerts before the first notification.
#
# A short group_wait will reduce the time to wait before sending the first
# notification for a new group of alerts. However, if group_wait is too short
# then the first notification might not contain the complete set of expected
# alerts, and alerts that should be inhibited might not be inhibited if the
# inhibiting alerts have not arrived in time.
#
# A long group_wait will increase the time to wait before sending the first
# notification for a new group of alerts. However, if group_wait is too long
# then notifications for firing alerts might not be sent within a reasonable
# time.
#
# If an alert is resolved before group_wait has elapsed, no notification will
# be sent for that alert. This reduces noise of flapping alerts.

# A notification for any alerts that missed the initial group_wait will be
# sent at the next group_interval instead.
#
# If omitted, child routes inherit the group_wait of the parent route.
[ group_wait: <duration> | default = 30s ]

# How long to wait before sending subsequent notifications for an existing
# group of alerts after group_wait.
#
# The group_interval is a recurring timer that starts as soon as group_wait
# has elapsed. At each group_interval, Alertmanager checks if any new alerts
# have fired or any firing alerts have resolved since the last group_interval,
# and if they have a notification is sent. If they haven't, Alertmanager checks
# if the repeat_interval has elapsed instead.
#
# Note: group_interval also sets the context timeout for the notification
# pipeline for each send. So if sending a notification takes longer than the
# group_interval, the notification will get canceled. This can happen with
# small group_interval values and slow notification receivers.
#
# If omitted, child routes inherit the group_interval of the parent route.
[ group_interval: <duration> | default = 5m ]

# How long to wait before repeating the last notification. Notifications are
# not repeated if any new alerts have fired or any firing alerts have resolved
# since the last group_interval.
#
# Since the repeat_interval is checked after each group_interval, it should
# be a multiple of the group_interval. If it's not, the repeat_interval
# is rounded up to the next multiple of the group_interval.
#
# In addition, if repeat_interval is longer then `--data.retention`, the
# notification will be repeated at the end of the data retention period
# instead.
#
# If omitted, child routes inherit the repeat_interval of the parent route.
[ repeat_interval: <duration> | default = 4h ]

# Times when the route should be muted. These must match the name of a
# time interval defined in the time_intervals section.
# Additionally, the root node cannot have any mute times.
# When a route is muted it will not send any notifications, but
# otherwise acts normally (including ending the route-matching process
# if the `continue` option is not set.)
mute_time_intervals:
  [ - <string> ...]

# Times when the route should be active. These must match the name of a
# time interval defined in the time_intervals section. An empty value
# means that the route is always active.
# Additionally, the root node cannot have any active times.
# The route will send notifications only when active, but otherwise
# acts normally (including ending the route-matching process
# if the `continue` option is not set).
active_time_intervals:
  [ - <string> ...]

# Zero or more child routes.
routes:
  [ - <route> ... ]

示例

# The root route with all parameters, which are inherited by the child
# routes if they are not overwritten.
route:
  receiver: 'default-receiver'
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  group_by: [cluster, alertname]
  # All alerts that do not match the following child routes
  # will remain at the root node and be dispatched to 'default-receiver'.
  routes:
  # All alerts with service=mysql or service=cassandra
  # are dispatched to the database pager.
  - receiver: 'database-pager'
    group_wait: 10s
    matchers:
    - service=~"mysql|cassandra"
  # All alerts with the team=frontend label match this sub-route.
  # They are grouped by product and environment rather than cluster
  # and alertname.
  - receiver: 'frontend-pager'
    group_by: [product, environment]
    matchers:
    - team="frontend"

  # All alerts with the service=inhouse-service label match this sub-route.
  # the route will be muted during offhours and holidays time intervals.
  # even if it matches, it will continue to the next sub-route
  - receiver: 'dev-pager'
    matchers:
      - service="inhouse-service"
    mute_time_intervals:
      - offhours
      - holidays
    continue: true

    # All alerts with the service=inhouse-service label match this sub-route
    # the route will be active only during offhours and holidays time intervals.
  - receiver: 'on-call-pager'
    matchers:
      - service="inhouse-service"
    active_time_intervals:
      - offhours
      - holidays

<time_interval>

time_interval 指定了一個命名的時間區間,可在路由樹中引用它來在一天中的特定時間靜默/啟用特定路由。

name: <string>
time_intervals:
  [ - <time_interval_spec> ... ]

<time_interval_spec>

time_interval_spec 包含了時間區間的實際定義。語法支援以下欄位

- times:
  [ - <time_range> ...]
  weekdays:
  [ - <weekday_range> ...]
  days_of_month:
  [ - <days_of_month_range> ...]
  months:
  [ - <month_range> ...]
  years:
  [ - <year_range> ...]
  location: <string>

所有欄位均為列表。在每個非空列表中,必須至少滿足一個元素才能匹配該欄位。如果某個欄位未指定,則任何值都將匹配該欄位。要使某個時刻與完整的時間區間相匹配,所有欄位都必須匹配。某些欄位支援範圍和負索引,具體說明如下。如果未指定時區,則時間預設為 UTC。

time_range:包含開始時間但不包含結束時間的範圍,以便於表示在整點開始/結束的時間。例如,start_time: '17:00'end_time: '24:00' 將從 17:00 開始,並在 24:00 之前結束。它們的指定方式如下

times:
- start_time: HH:MM
  end_time: HH:MM

weekday_range:星期幾的列表,星期從星期日開始到星期六結束。星期應透過名稱指定(例如 'Sunday')。為方便起見,也接受格式為 <start_day>:<end_day> 的範圍,且兩端均包含。例如:['monday:wednesday','saturday', 'sunday']

days_of_month_range:月中天數的數字列表。天數從 1 開始。也接受從月底開始倒數的負值,例如 1 月份的 -1 將代表 1 月 31 日。例如:['1:5', '-3:-1']。超出該月開始或結束的部分將被截斷。例如,在 2 月份指定 ['1:31'] 會將實際結束日期限制為 28 或 29(取決於是否是閏年)。兩端均包含。

month_range:日曆月份列表,透過不區分大小寫的名稱(例如 'January')或數字指定,其中 January = 1。也接受範圍。例如,['1:3', 'may:august', 'december']。兩端均包含。

year_range:年份的數字列表。接受範圍。例如,['2020:2022', '2030']。兩端均包含。

location:匹配 IANA 時區資料庫中位置的字串。例如 'Australia/Sydney'。該位置為時間區間提供時區。例如,位置為 'Australia/Sydney' 的時間區間如果包含類似以下內容

times:
- start_time: 09:00
  end_time: 17:00
weekdays: ['monday:friday']

將包括在澳大利亞悉尼當地時間週一至週五上午 9:00 至下午 5:00 之間的任何時間。

您還可以將 'Local' 作為位置,以使用執行 Alertmanager 的機器的本地時間,或者使用 'UTC' 表示 UTC 時間。如果未提供時區,則時間區間預設為 UTC 時間。注意:在 Windows 上,除非您使用 ZONEINFO 環境變數提供自定義時區資料庫,否則僅支援 LocalUTC

抑制允許在存在另一組告警時靜默一組告警。這有助於在系統或服務之間建立依賴關係,從而在發生故障時,只發送一組互相關聯的告警中最相關的那條。

有關抑制的更多資訊,請參閱 Alertmanager 概念

<inhibit_rule>

當存在匹配另一組匹配器的源告警(source)時,抑制規則會靜默匹配一組匹配器的目標告警(target)。目標告警和源告警在 equal 列表中的標籤名必須具有相同的標籤值。

從語義上講,缺失的標籤和具有空值的標籤是相同的。因此,如果源告警 and 目標告警都缺失了 equal 中列出的所有標籤名,則抑制規則將適用。

為了防止告警抑制其自身,同時匹配規則的目標端源端的告警,不能被同樣符合此情況的告警(包括其自身)所抑制。然而,我們建議在選擇目標和源匹配器時,儘量使告警永遠不會同時匹配兩端。這更容易推理,且不會觸發此特例。

# Optional name of the inhibition rule.
# Duplicate names are allowed but will affect the per-rule metrics.
name: <string>

# DEPRECATED: Use target_matchers below.
# Matchers that have to be fulfilled in the alerts to be muted.
target_match:
  [ <labelname>: <labelvalue>, ... ]
# DEPRECATED: Use target_matchers below.
target_match_re:
  [ <labelname>: <regex>, ... ]

# A list of matchers that have to be fulfilled by the target
# alerts to be muted.
target_matchers:
  [ - <matcher> ... ]

# DEPRECATED: Use source_matchers below.
# Matchers for which one or more alerts have to exist for the
# inhibition to take effect.
source_match:
  [ <labelname>: <labelvalue>, ... ]
# DEPRECATED: Use source_matchers below.
source_match_re:
  [ <labelname>: <regex>, ... ]

# A list of matchers for which one or more alerts have
# to exist for the inhibition to take effect.
source_matchers:
  [ - <matcher> ... ]

# Labels that must have an equal value in the source and target
# alert for the inhibition to take effect.
[ equal: '[' <labelname>, ... ']' ]

標籤匹配器

標籤匹配器用於將告警匹配到路由、靜默和抑制規則。

重要提示:Prometheus 正在增加對標籤和指標中 UTF-8 的支援。為了在 Alertmanager 中也支援 UTF-8,Alertmanager 0.27 及更高版本引入了新的匹配器解析器,該解析器包含若干向後不相容的更改。雖然大多數匹配器都將向前相容,但有些則不會。Alertmanager 正在實行過渡期,在此期間同時支援 UTF-8 匹配器和經典匹配器,並提供了許多工具來幫助您為過渡做好準備。

如果這是全新安裝的 Alertmanager,我們建議在建立 Alertmanager 配置檔案之前啟用 UTF-8 嚴格模式。您可以在此處找到有關如何啟用 UTF-8 嚴格模式的說明。

如果是現有的 Alertmanager 安裝,我們建議在啟用 UTF-8 嚴格模式之前,先在名為回退模式(fallback mode)的預設模式下執行 Alertmanager。在此模式下,如果需要對配置檔案進行更改才能啟用 UTF-8 嚴格模式,Alertmanager 將記錄警告。Alertmanager 將在接下來的兩個版本中將 UTF-8 嚴格模式作為預設模式,因此儘快進行過渡非常重要。

無論 Alertmanager 是全新安裝還是現有安裝,您都可以在 Alertmanager 服務端中啟用 UTF-8 嚴格模式之前,使用 amtool 驗證其配置檔案是否相容該模式。此操作不需要執行 Alertmanager 服務。您可以在此處找到有關如何使用 amtool 驗證 Alertmanager 配置檔案的說明。

Alertmanager 服務端執行模式

在過渡期內,Alertmanager 支援三種執行模式。它們被稱為回退模式(fallback mode)、UTF-8 嚴格模式(UTF-8 strict mode)和經典模式(classic mode)。回退模式是預設模式。

Alertmanager 服務端的運維人員應在過渡期結束前過渡到 UTF-8 嚴格模式。Alertmanager 將在接下來的兩個版本中將 UTF-8 嚴格模式作為預設模式,因此儘快進行過渡非常重要。

回退模式

Alertmanager 預設執行在名為回退模式的特殊模式下。作為運維人員,您應該不會感受到路由、靜默或抑制規則的執行方式有任何差異。

在回退模式下,配置首先被解析為 UTF-8 匹配器,如果與 UTF-8 解析器不相容,則會被解析為經典匹配器。如果您的 Alertmanager 配置包含與 UTF-8 解析器不相容的匹配器,Alertmanager 將把它們解析為經典匹配器並記錄警告。該警告還包含如何將經典匹配器更改為 UTF-8 匹配器的建議。例如

ts=2024-02-11T10:00:00Z caller=parse.go:176 level=warn msg="Alertmanager is moving to a new parser for labels and matchers, and this input is incompatible. Alertmanager has instead parsed the input using the classic matchers parser as a fallback. To make this input compatible with the UTF-8 matchers parser please make sure all regular expressions and values are double-quoted and backslashes are escaped. If you are still seeing this message please open an issue." input="foo=" origin=config err="end of input: expected label value" suggestion="foo=\"\""

在這裡,匹配器 foo= 可以透過對錶達式右側加雙引號變為 foo="" 來使其成為有效的 UTF-8 匹配器。這兩個匹配器是等價的,但是在 UTF-8 匹配器中,匹配器的右側是必填欄位。

在極少數情況下,配置可能會導致 UTF-8 解析器和經典解析器之間產生分歧。這發生在匹配器在兩個解析器中都有效,但由於增加了對 UTF-8 的支援,導致根據所使用的解析器產生不同的解析結果。如果您的 Alertmanager 配置存在分歧,Alertmanager 將使用經典解析器並記錄警告。例如

ts=2024-02-11T10:00:00Z caller=parse.go:183 level=warn msg="Matchers input has disagreement" input="qux=\"\\xf0\\x9f\\x99\\x82\"\n" origin=config

任何出現分歧的情況都應該逐案分析,因為根據分歧的性質,在啟用 UTF-8 嚴格模式之前,配置可能不需要更新。例如 \xf0\x9f\x99\x82 是 🙂 表情符號的位元組序列。如果目的是匹配字面上的 🙂 表情符號,則無需更改。然而,如果目的是匹配字面上的 \xf0\x9f\x99\x82,則應將匹配器更改為 qux="\\xf0\\x9f\\x99\\x82"

UTF-8 嚴格模式

在 UTF-8 嚴格模式下,Alertmanager 會停用對經典匹配器的支援

alertmanager --config.file=config.yml --enable-feature="utf8-strict-mode"

此模式應適用於新的 Alertmanager 安裝,以及所有不相容匹配器警告均已解決的現有 Alertmanager 安裝。在所有不相容匹配器的警告得到解決之前,Alertmanager 將無法在 UTF-8 嚴格模式下啟動

ts=2024-02-11T10:00:00Z caller=coordinator.go:118 level=error component=configuration msg="Loading configuration file failed" file=config.yml err="end of input: expected label value"

在過渡期結束時,UTF-8 嚴格模式將成為 Alertmanager 的預設模式。

經典模式

經典模式等同於 Alertmanager 0.26.0 及更早版本

alertmanager --config.file=config.yml --enable-feature="classic-mode"

如果您懷疑回退模式或 UTF-8 嚴格模式存在問題,可以使用此模式。在這種情況下,請在 GitHub 上開一個 issue,並提供儘可能多的資訊。

驗證

您可以在 Alertmanager 服務端中啟用 UTF-8 嚴格模式之前,使用 amtool 驗證配置檔案是否相容該模式。此操作不需要執行 Alertmanager 服務。

與 Alertmanager 服務端一樣,如果配置不相容或存在分歧,amtool 將記錄一條警告

amtool check-config config.yml
Checking 'config.yml'
level=warn msg="Alertmanager is moving to a new parser for labels and matchers, and this input is incompatible. Alertmanager has instead parsed the input using the classic matchers parser as a fallback. To make this input compatible with the UTF-8 matchers parser please make sure all regular expressions and values are double-quoted and backslashes are escaped. If you are still seeing this message please open an issue." input="foo=" origin=config err="end of input: expected label value" suggestion="foo=\"\""
level=warn msg="Matchers input has disagreement" input="qux=\"\\xf0\\x9f\\x99\\x82\"\n" origin=config
  SUCCESS
Found:
 - global config
 - route
 - 2 inhibit rules
 - 2 receivers
 - 0 templates

amtool 中沒有記錄警告時,您就會知道配置是相容 UTF-8 嚴格模式的

amtool check-config config.yml
Checking 'config.yml'  SUCCESS
Found:
 - global config
 - route
 - 2 inhibit rules
 - 2 receivers
 - 0 templates

您還可以在 UTF-8 嚴格模式下使用 amtool 作為額外的驗證。如果命令失敗,您就會知道配置是無效的

amtool check-config config.yml --enable-feature="utf8-strict-mode"
level=warn msg="UTF-8 mode enabled"
Checking 'config.yml'  FAILED: end of input: expected label value

amtool: error: failed to validate 1 file(s)

如果命令成功,您就會知道配置是有效的

amtool check-config config.yml --enable-feature="utf8-strict-mode"
level=warn msg="UTF-8 mode enabled"
Checking 'config.yml'  SUCCESS
Found:
 - global config
 - route
 - 2 inhibit rules
 - 2 receivers
 - 0 templates

<matcher>(共享)

UTF-8 匹配器

一個 UTF-8 匹配器由三個標記(token)組成

  • 用於標籤名稱的未加引號的字面量或加雙引號的字串。
  • =!==~!~ 之一。= 表示等於,!= 表示不等於,=~ 表示匹配正則表示式,!~ 表示不匹配正則表示式。
  • 用於正則表示式或標籤值的未加引號的字面量或加雙引號的字串。

未加引號的字面量可以包含除保留字元以外的所有 UTF-8 字元。保留字元包括空白字元以及 { } ! = ~ , \ " ' ` 中的所有字元。例如,foo[a-zA-Z]+Προμηθεύς(希臘語的 Prometheus)都是有效的未加引號字面量的例子。然而,foo! 不是一個有效的字面量,因為 ! 是保留字元。

加雙引號的字串可以包含所有 UTF-8 字元。與未加引號的字面量不同,它沒有保留字元。然而,字面上的雙引號和反斜槓必須用單個反斜槓轉義。例如,為了匹配正則表示式 \d+,反斜槓必須轉義為 "\\d+"。這是因為雙引號字串遵循與 Go 語言的 字串字面量  相同的規則。雙引號字串也支援 UTF-8 碼位。例如,"foo!""bar,baz""\"baz qux\"""\xf0\x9f\x99\x82"

注意:YAML 引號與匹配器標記(token)引號的對比

matchers: 列表中的每個條目都是一個單一的 YAML 字串,Alertmanager 會在 YAML 檔案處理完畢後對其進行解析。YAML 的引號作用於整個匹配器字串——它不會解析或保護其中的單個標記(token)。上述的雙引號是由 Alertmanager 自身的解析器在 YAML 已經處理完輸入之後進行處理的。

  • 純樣式 (無外包引號):適用於匹配器不包含 YAML 特殊字元({, }, [, ], ,, #, |, >, :)的情況。示例:env !~ preprod
  • 單引號樣式 :防止所有 YAML 特殊字元的影響,並允許在匹配器內部使用字面雙引號。示例:'env =~ "prod|staging"'
  • 雙引號樣式 :支援 YAML 轉義序列;值內部的字面雙引號必須轉義為 \"。示例:"env !~ \"uat\""

在沒有外層 YAML 引號的情況下寫入 env =~ "prod" 是有效的純樣式 YAML。內部的雙引號會被 Alertmanager 的解析器剝離,並且對於 YAML 特殊字元不提供任何保護。當值可能包含特殊字元時,請始終在 YAML 級別對整個匹配器加引號。

經典匹配器

經典匹配器是一個語法靈感來自 PromQL 和 OpenMetrics 的字串。經典匹配器的語法由三個標記(token)組成

  • 一個有效的 Prometheus 標籤名稱。
  • =!==~!~ 之一。= 表示等於,!= 表示字串不相等,=~ 用於正則等價匹配,!~ 用於正則不等價匹配。它們的含義與 PromQL 選擇器中的含義相同。
  • 一個 UTF-8 字串,可以用雙引號括起來。每個標記的前後可以有任意數量的空白字元。

第三個標記可以是空字串。在第三個標記中,適用 OpenMetrics 轉義規則:\" 表示雙引號,\n 表示換行符,\\ 表示字面上的反斜槓。未轉義的 " 不能出現在第三個標記內部(只能作為第一個或最後一個字元)。然而,字面換行符是被允許的,未跟隨 \n" 的單個 \ 字元也是被允許的。在這種情況下,它們作為字面反斜槓起作用。

匹配器的組合

您可以組合匹配器以建立複雜的匹配表示式。在組合時,所有匹配器都必須匹配,整個表示式才算匹配。例如,表示式 {alertname="Watchdog", severity=~"warning|critical"} 將匹配帶有標籤 alertname=Watchdog, severity=critical 的告警,但不會匹配帶有標籤 alertname=Watchdog, severity=none 的告警,因為雖然 alertname 是 Watchdog,但 severity 既不是 warning 也不是 critical。

您可以使用 YAML 列表將匹配器組合到表示式中

matchers:
  - alertname = Watchdog
  - severity =~ "warning|critical"

或者作為一個受 PromQL 啟發的表示式,其中每個匹配器由逗號分隔

{alertname="Watchdog", severity=~"warning|critical"}

允許有單個尾隨逗號

{alertname="Watchdog", severity=~"warning|critical",}

左大括號 { 和右大括號 } 是可選的

alertname="Watchdog", severity=~"warning|critical"

但是,兩者必須同時存在或同時省略。不能只有不完整的左大括號或右大括號

{alertname="Watchdog", severity=~"warning|critical"
alertname="Watchdog", severity=~"warning|critical"}

也不能有重複的左大括號或右大括號

{{alertname="Watchdog", severity=~"warning|critical",}}

在雙引號之外允許使用空白字元(空格、製表符和換行符),並且對匹配器本身沒有影響。例如

{
   alertname = "Watchdog",
   severity =~ "warning|critical",
}

等同於

{alertname="Watchdog",severity=~"warning|critical"}

更多示例

這裡有一些更多的示例

  1. 組合為 YAML 列表的兩個等於匹配器

    matchers:
      - foo = bar
      - dings != bums
  2. 組合為簡短形式 YAML 列表的兩個匹配器

    matchers: [ foo = bar, dings != bums ]

    如下所示,在簡短形式中,最好使用雙引號以避免諸如逗號之類的特殊字元帶來的問題

    matchers: [ "foo = \"bar,baz\"", "dings != bums" ]
  3. 您也可以將兩個匹配器放入一個類似於 PromQL 的字串中。在這裡,單引號效果最好

    matchers: [ '{foo="bar", dings!="bums"}' ]
  4. 為了避免 YAML 中轉義和引號規則的問題,您還可以使用 YAML 塊

    matchers:
      - |
          {quote=~"She said: \"Hi, all!( How're you…)?\""}

這些接收器設定允許配置通知目的地(接收器)以及基於 HTTP 的接收器的 HTTP 客戶端選項。

<receiver>

接收器(Receiver)是一個或多個通知整合的命名配置。

注意:作為解除過去對新接收器暫停審批政策的一部分,各方達成一致,除了現有要求外,新的通知整合還需要有一名擁有推送許可權的專屬維護者。

# The unique name of the receiver.
name: <string>

# Labels attached to this receiver for querying and filtering.
labels:
  [ <labelname>: <labelvalue>, ... ]

# Configurations for several notification integrations.
discord_configs:
  [ - <discord_config>, ... ]
email_configs:
  [ - <email_config>, ... ]
mattermost_configs:
  [ - <mattermost_config>, ... ]
msteams_configs:
  [ - <msteams_config>, ... ]
msteamsv2_configs:
  [ - <msteamsv2_config>, ... ]
jira_configs:
  [ - <jira_config>, ... ]
opsgenie_configs:
  [ - <opsgenie_config>, ... ]
pagerduty_configs:
  [ - <pagerduty_config>, ... ]
incidentio_configs:
  [ - <incidentio_config>, ... ]
pushover_configs:
  [ - <pushover_config>, ... ]
rocketchat_configs:
  [ - <rocketchat_config>, ... ]
slack_configs:
  [ - <slack_config>, ... ]
sns_configs:
  [ - <sns_config>, ... ]
telegram_configs:
  [ - <telegram_config>, ... ]
victorops_configs:
  [ - <victorops_config>, ... ]
webex_configs:
  [ - <webex_config>, ... ]
webhook_configs:
  [ - <webhook_config>, ... ]
wechat_configs:
  [ - <wechat_config>, ... ]

<http_config>(共享)

http_config 允許配置接收器用於與基於 HTTP 的 API 服務進行通訊的 HTTP 客戶端。

# Note that `basic_auth` and `authorization` options are mutually exclusive.

# Sets the `Authorization` header with the configured username and password.
# password and password_file are mutually exclusive.
basic_auth:
  [ username: <string> ]
  [ password: <secret> ]
  [ password_file: <string> ]

# Optional the `Authorization` header configuration.
authorization:
  # Sets the authentication type.
  [ type: <string> | default: Bearer ]
  # Sets the credentials. It is mutually exclusive with
  # `credentials_file`.
  [ credentials: <secret> ]
  # Sets the credentials with the credentials read from the configured file.
  # It is mutually exclusive with `credentials`.
  [ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
  [ <oauth2> ]

# Whether to enable HTTP2.
[ enable_http2: <bool> | default: true ]

# Optional proxy URL.
[ proxy_url: <string> ]
# Comma-separated string that can contain IPs, CIDR notation, domain names
# that should be excluded from proxying. IP and domain names can
# contain port numbers.
[ no_proxy: <string> ]
# Use proxy URL indicated by environment variables (HTTP_PROXY, http_proxy, HTTPS_PROXY, https_proxy, NO_PROXY, and no_proxy)
[ proxy_from_environment: <boolean> | default: false ]
# Specifies headers to send to proxies during CONNECT requests.
[ proxy_connect_header:
  [ <string>: [<secret>, ...] ] ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <bool> | default = true ]

# Configures the TLS settings.
tls_config:
  [ <tls_config> ]

# Custom HTTP headers to be sent along with each request.
# Headers that are set by Prometheus itself can't be overwritten.
http_headers:
  [ <http_header> ]

<http_header>(共享)

# Header name.
<string>:
    # Header values.
    [ values: [<string>, ...] ]
    # Headers values. Hidden in configuration page.
    [ secrets: [<secret>, ...] ]
    # Files to read header values from.
    [ files: [<string>, ...] ]

<oauth2>(共享)

使用客戶端憑證(client credentials)授權型別的 OAuth 2.0 認證。Alertmanager 使用給定的客戶端訪問金鑰和客戶端金鑰(secret key)從指定的端點獲取訪問令牌(access token)。

client_id: <string>
[ client_secret: <secret> ]

# Read the client secret from a file.
# It is mutually exclusive with `client_secret`.
[ client_secret_file: <filename> ]

# Scopes for the token request.
scopes:
  [ - <string> ... ]

# The URL to fetch the token from.
token_url: <string>

# Optional parameters to append to the token URL.
endpoint_params:
  [ <string>: <string> ... ]

# Configures the token request's TLS settings.
tls_config:
  [ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]
# Comma-separated string that can contain IPs, CIDR notation, domain names
# that should be excluded from proxying. IP and domain names can
# contain port numbers.
[ no_proxy: <string> ]
# Use proxy URL indicated by environment variables (HTTP_PROXY, https_proxy, HTTPs_PROXY, https_proxy, and no_proxy)
[ proxy_from_environment: <boolean> | default: false ]
# Specifies headers to send to proxies during CONNECT requests.
[ proxy_connect_header:
  [ <string>: [<secret>, ...] ] ]

<tls_config>(共享)

tls_config 允許配置 TLS 連線。

# CA certificate to validate the server certificate with.
[ ca_file: <filepath> ]

# Certificate and key files for client cert authentication to the server.
[ cert_file: <filepath> ]
[ key_file: <filepath> ]

# ServerName extension to indicate the name of the server.
# http://tools.ietf.org/html/rfc4366#section-3.1
[ server_name: <string> ]

# Disable validation of the server certificate.
[ insecure_skip_verify: <boolean> | default = false]

# Minimum acceptable TLS version. Accepted values: TLS10 (TLS 1.0), TLS11 (TLS
# 1.1), TLS12 (TLS 1.2), TLS13 (TLS 1.3).
# If unset, Prometheus will use Go default minimum version, which is TLS 1.2.
# See MinVersion in https://pkg.go.dev/crypto/tls#Config.
[ min_version: <string> ]
# Maximum acceptable TLS version. Accepted values: TLS10 (TLS 1.0), TLS11 (TLS
# 1.1), TLS12 (TLS 1.2), TLS13 (TLS 1.3).
# If unset, Prometheus will use Go default maximum version, which is TLS 1.3.
# See MaxVersion in https://pkg.go.dev/crypto/tls#Config.
[ max_version: <string> ]

接收器整合設定

這些設定允許配置特定的接收器整合。

<discord_config>

Discord 通知是透過 Discord webhook API  傳送的。請參閱 Discord 的 “網路鉤子入門(Intro to Webhooks)”文章 ,以瞭解如何為頻道配置網路鉤子整合。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The Discord webhook URL.
# webhook_url and webhook_url_file are mutually exclusive.
webhook_url: <secret>
webhook_url_file: <filepath>

# Message title template.
[ title: <tmpl_string> | default = '{{ template "discord.default.title" . }}' ]

# Message body template.
[ message: <tmpl_string> | default = '{{ template "discord.default.message" . }}' ]

# Message content template. Limited to 2000 characters.
[ content: <tmpl_string> | default = '{{ template "discord.default.content" . }}' ]

# Message username.
[ username: <string> | default = '' ]

# Message avatar URL.
[ avatar_url: <string> | default = '' ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<email_config>

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = false ]

# The email address to send notifications to.
# Allows a comma separated list of rfc5322 compliant email addresses.
to: <tmpl_string>

# The sender's address.
[ from: <tmpl_string> | default = global.smtp_from ]

# The SMTP host through which emails are sent.
[ smarthost: <string> | default = global.smtp_smarthost ]

# The hostname to identify to the SMTP server.
[ hello: <string> | default = global.smtp_hello ]

# SMTP authentication information.
# auth_password and auth_password_file are mutually exclusive.
# auth_secret and auth_secret_file are mutually exclusive.
[ auth_username: <string> | default = global.smtp_auth_username ]
[ auth_password: <secret> | default = global.smtp_auth_password ]
[ auth_password_file: <string> | default = global.smtp_auth_password_file ]
[ auth_secret: <secret> | default = global.smtp_auth_secret ]
[ auth_secret_file: <secret> | default = global.smtp_auth_secret_file ]
[ auth_identity: <string> | default = global.smtp_auth_identity ]

# The SMTP TLS requirement.
# Note that Go does not support unencrypted connections to remote SMTP endpoints.
[ require_tls: <bool> | default = global.smtp_require_tls ]

# Force use of implicit TLS (direct TLS connection) for better security.
# true: force use of implicit TLS (direct TLS connection on any port)
# nil (default): auto-detect based on port (465=implicit, other=explicit) for backward compatibility
[ force_implicit_tls: <bool> | default = nil ]

# TLS configuration.
tls_config:
  [ <tls_config> | default = global.smtp_tls_config ]

# The HTML body of the email notification.
[ html: <tmpl_string> | default = '{{ template "email.default.html" . }}' ]
# The text body of the email notification.
[ text: <tmpl_string> ]

# Further headers email header key/value pairs. Overrides any headers
# previously set by the notification implementation.
[ headers: { <string>: <tmpl_string>, ... } ]

# Email threading configuration.
threading:
  # Whether to enable threading, which makes alert notifications in the same
  # alert group show up in the same email thread.
  [ enabled: <boolean> | default = false ]
  # What granularity of current date to thread by. Accepted values: daily, none.
  # (none means group by alert group key, no date).
  [ thread_by_date: <string> | default = daily ]

Email TLS 配置示例

# Example 1: Force implicit TLS on any port (recommended for security)
receivers:
  - name: email-implicit-tls
    email_configs:
      - to: [email protected]
        smarthost: smtp.example.com:8465
        force_implicit_tls: true  # Use direct TLS connection on port 8465

# Example 2: Backward compatible (no force_implicit_tls specified)
receivers:
  - name: email-default
    email_configs:
      - to: [email protected]
        smarthost: smtp.example.com:465  # Auto-detects implicit TLS
      - to: [email protected]
        smarthost: smtp.example.com:587  # Auto-detects explicit TLS

<mattermost_config>

Mattermost 通知透過 Mattermost Webhook API  傳送。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The Mattermost webhook URL.
# webhook_url and webhook_url_file are mutually exclusive.
webhook_url: <secret>
webhook_url_file: <filepath>

# Overrides the channel the message posts in. Use the channel’s name and not the display name, e.g. use town-square, not Town Square.
[ channel: <string> | default = '' ]

# Overrides the username the message posts as.
# Defaults to the username set during webhook creation; if no username was set during creation, webhook is used.
[ username: <string> | default = '' ]

# Overrides the profile picture the message posts with.
[ icon_url: <string> | default = '' ]

# Overrides the profile picture and icon_url parameter.
[ icon_emoji: <string> | default = '' ]

# Message attachments used for richer formatting options.
# It is for compatibility with Slack.
[ fallback: <tmpl_string> | default = '{{ template "mattermost.default.fallback" . }}' ]
[ color: <tmpl_string> | default = '{{ template "mattermost.default.color" . }}' ]
[ title: <tmpl_string> | default = '{{ template "mattermost.default.title" . }}' ]
[ title_link: <tmpl_string> | default = '{{ template "mattermost.default.titlelink" . }}' ]
[ text: <tmpl_string> | default = '{{ template "mattermost.default.text" . }}' ]
[ pretext: <string> | default = '' ]
[ author_name: <string> | default = '' ]
[ author_link: <string> | default = '' ]
[ author_icon: <string> | default = '' ]
[ fields: <string> | default = '' ]
  [ <field_config> ... ]
[ thumb_url: <string> | default = '' ]
[ footer: <string> | default = '' ]
[ footer_icon: <string> | default = '' ]
[ image_url: <string> | default = '' ]
# Deprecated: use top-level fields instead; `attachments` will be removed in a future.
[ attachments: ]
  [ <attachment_config> ... ]

[ props: <prop_config> ]

[ priority: <priority_config> ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<attachment_config>

請參閱 Mattermost 文件  以獲取更多資訊。

[ fallback: <string> | default = '' ]
[ color: <string> | default = '' ]
[ pretext: <string> | default = '' ]
[ text: <string> | default = '' ]
[ author_name: <string> | default = '' ]
[ author_link: <string> | default = '' ]
[ author_icon: <string> | default = '' ]
[ title: <string> | default = '' ]
[ title_link: <string> | default = '' ]
# Same as Slack fields.
[ fields: <string> | default = '' ]
  [ <field_config> ... ]
[ thumb_url: <string> | default = '' ]
[ footer: <string> | default = '' ]
[ footer_icon: <string> | default = '' ]
[ image_url: <string> | default = '' ]

<prop_config>

# Props card allows for extra information (Markdown-formatted text) to be sent to Mattermost that will only be displayed in the RHS panel after a user selects the info icon displayed alongside the post.
[ card: <string> | default = '' ]

<priority_config>

# priority adds label to the message. Possible values are "urgent", "important" and "standard".
[ priority: <string> | default = '' ]

# If set to true, the message will be marked as requiring an acknowledgment from the users by displaying a checkmark icon next to the message. Keep in mind that this requires the message priority to be set to Important or Urgent.
# Only for enterprise version of Mattermost.
[ requested_ack: <bool> | default = false ]

# Only for Urgent messages. If set to true recipients will receive a persistent notification every five minutes until they acknowledge the message.
# Only for enterprise version of Mattermost.
[ persistent_notifications: <bool> | default = false ]

<msteams_config>

Microsoft Teams 通知透過 Incoming Webhooks  API 端點發送。

棄用通知:Microsoft 正在棄用透過 Microsoft Teams 建立和使用 Microsoft 365 聯結器 。請考慮遷移至配合 msteamsv2 配置使用 工作流 (Workflows) 

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The incoming webhook URL.
# webhook_url and webhook_url_file are mutually exclusive.
[ webhook_url: <secret> ]
[ webhook_url_file: <filepath> ]

# Message title template.
[ title: <tmpl_string> | default = '{{ template "msteams.default.title" . }}' ]

# Message summary template.
[ summary: <tmpl_string> | default = '{{ template "msteams.default.summary" . }}' ]

# Message body template.
[ text: <tmpl_string> | default = '{{ template "msteams.default.text" . }}' ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<msteamsv2_config>

Microsoft Teams v2 通知,使用的是 流 (flows)  所要求的自適應卡片新訊息格式。請按照 此文件  以獲取有關如何設定此整合的更多資訊。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The incoming webhook URL.
# webhook_url and webhook_url_file are mutually exclusive.
[ webhook_url: <secret> ]
[ webhook_url_file: <filepath> ]

# Message title template.
[ title: <tmpl_string> | default = '{{ template "msteamsv2.default.title" . }}' ]

# Message body template.
[ text: <tmpl_string> | default = '{{ template "msteamsv2.default.text" . }}' ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<jira_config>

JIRA 通知透過 JIRA Rest API v2 JIRA REST API v3  傳送。

注意:此整合僅在 Jira Cloud 例項上進行過測試。Jira Data Center(本地部署例項)可能也可以工作,但不保證其可行性。

兩個 API 具有相同的功能集。區別在於 V2 的問題描述支援 Wiki 標記 (Wiki Markup) ,而 V3 支援 Atlassian 文件格式 (ADF) 。預設的 jira.default.description 模板僅適用於 V2。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The URL to send API requests to. The full API path must be included.
# Example: https://company.atlassian.net/rest/api/2/
[ api_url: <string> | default = global.jira_api_url ]

# The API Type to use for search requests, can be either auto, cloud or datacenter
# Example: cloud
[ api_type: <string> | default = auto ]

# The project key where issues are created.
project: <string>

# Issue summary configuration.
[ summary:
    # Template for the issue summary.
    [ template: <tmpl_string> | default = '{{ template "jira.default.summary" . }}' ]

    # If set to false, the summary will not be updated when updating an existing issue.
    [ enable_update: <boolean> | default = true ]
]

# Issue description configuration.
[ description:
    # Template for the issue description.
    [ template: <tmpl_string> | default = '{{ template "jira.default.description" . }}' ]

    # If set to false, the description will not be updated when updating an existing issue.
    [ enable_update: <boolean> | default = true ]
]

# Labels to be added to the issue.
labels:
  [ - <tmpl_string> ... ]

# Priority of the issue.
[ priority: <tmpl_string> | default = '{{ template "jira.default.priority" . }}' ]

# Type of the issue (e.g. Bug).
[ issue_type: <string> ]

# Name of the workflow transition to resolve an issue. The target status must have the category "done".
# NOTE: The name of the transition can be localized and depends on the language setting of the service account.
[ resolve_transition: <string> ]

# Name of the workflow transition to reopen an issue. The target status should not have the category "done".
# NOTE: The name of the transition can be localized and depends on the language setting of the service account.
[ reopen_transition: <string> ]

# If reopen_transition is defined, ignore issues with that resolution.
[ wont_fix_resolution: <string> ]

# If reopen_transition is defined, reopen the issue when it is not older than this value (rounded down to the nearest minute).
# The resolutiondate field is used to determine the age of the issue.
[ reopen_duration: <duration> ]

# Other issue and custom fields.
fields:
  [ <string>: <jira_field> ... ]


# The HTTP client's configuration. You must use this configuration to supply the personal access token (PAT) as part of the HTTP `Authorization` header.
# For Jira Cloud, use basic_auth with the email address as the username and the PAT as the password.
# For Jira Data Center, use the 'authorization' field with 'credentials: <PAT value>'.
[ http_config: <http_config> | default = global.http_config ]

labels 欄位是新增到問題的標籤列表。支援模板表示式。例如

labels:
  - 'alertmanager'
  - '{{ .CommonLabels.severity }}'

<jira_field>

Jira 問題欄位可以有多種型別。根據欄位型別的不同,必須以不同的方式提供值。請參閱 https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#setting-custom-field-data-for-other-field-types  以獲取更多示例。

fields:
    # Components
    components: { name: "Monitoring" }
    # Custom Field TextField
    customfield_10001: "Random text"
    # Custom Field SelectList
    customfield_10002: {"value": "red"}
    # Custom Field MultiSelect
    customfield_10003: [{"value": "red"}, {"value": "blue"}, {"value": "green"}]

<opsgenie_config>

OpsGenie 通知透過 OpsGenie API  傳送。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The API key to use when talking to the OpsGenie API.
[ api_key: <secret> | default = global.opsgenie_api_key ]

# The filepath to API key to use when talking to the OpsGenie API. Conflicts with api_key.
[ api_key_file: <filepath> | default = global.opsgenie_api_key_file ]

# The base URL for OpsGenie API requests.
[ api_url: <string> | default = global.opsgenie_api_url ]

# Alert text limited to 130 characters.
[ message: <tmpl_string> | default = '{{ template "opsgenie.default.message" . }}' ]

# A description of the alert.
[ description: <tmpl_string> | default = '{{ template "opsgenie.default.description" . }}' ]

# A backlink to the sender of the notification.
[ source: <tmpl_string> | default = '{{ template "opsgenie.default.source" . }}' ]

# A set of arbitrary key/value pairs that provide further detail
# about the alert.
# All common labels are included as details by default.
[ details: { <string>: <tmpl_string>, ... } ]

# List of responders responsible for notifications.
responders:
  [ - <responder> ... ]

# Comma separated list of tags attached to the notifications.
[ tags: <tmpl_string> ]

# Additional alert note.
[ note: <tmpl_string> ]

# Priority level of alert. Possible values are P1, P2, P3, P4, and P5.
[ priority: <tmpl_string> ]

# Whether to update message and description of the alert in OpsGenie if it already exists
# By default, the alert is never updated in OpsGenie, the new message only appears in activity log.
[ update_alerts: <boolean> | default = false ]

# Optional field that can be used to specify which domain alert is related to.
[ entity: <tmpl_string> ]

# Comma separated list of actions that will be available for the alert.
[ actions: <tmpl_string> ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<responder>

# Exactly one of these fields should be defined.
[ id: <tmpl_string> ]
[ name: <tmpl_string> ]
[ username: <tmpl_string> ]

# One of `team`, `teams`, `user`, `escalation` or `schedule`.
#
# The `teams` responder is configured using the `name` field above.
# This field can contain a comma-separated list of team names.
# If the list is empty, no responders are configured.
type: <tmpl_string>

<pagerduty_config>

PagerDuty 通知透過 PagerDuty API  傳送。PagerDuty 提供了關於如何整合的 文件 。Alertmanager v0.11 及更高版本對 PagerDuty Events API v2 的支援存在重要差異。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The routing and service keys are mutually exclusive.
# The PagerDuty integration key (when using PagerDuty integration type `Events API v2`).
# It is mutually exclusive with `routing_key_file`.
routing_key: <tmpl_secret>
# Read the Pager Duty routing key from a file.
# It is mutually exclusive with `routing_key`.
routing_key_file: <filepath>
# The PagerDuty integration key (when using PagerDuty integration type `Prometheus`).
# It is mutually exclusive with `service_key_file`.
service_key: <tmpl_secret>
# Read the Pager Duty service key from a file.
# It is mutually exclusive with `service_key`.
service_key_file: <filepath>

# The URL to send API requests to
[ url: <string> | default = global.pagerduty_url ]

# The client identification of the Alertmanager.
[ client:  <tmpl_string> | default = '{{ template "pagerduty.default.client" . }}' ]
# A backlink to the sender of the notification.
[ client_url:  <tmpl_string> | default = '{{ template "pagerduty.default.clientURL" . }}' ]

# A description of the incident.
[ description: <tmpl_string> | default = '{{ template "pagerduty.default.description" .}}' ]

# Severity of the incident.
[ severity: <tmpl_string> | default = 'error' ]

# Unique location of the affected system.
[ source: <tmpl_string> | default = client ]

# A set of arbitrary key/value pairs that provide further detail about the incident.
# Nested key/value pairs are accepted when using PagerDuty integration type `Events API v2`.
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ .Alerts.Firing | toJSON }}'
  resolved:     '{{ .Alerts.Resolved | toJSON }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]

# Images to attach to the incident.
images:
  [ <image_config> ... ]

# Links to attach to the incident.
links:
  [ <link_config> ... ]

# The part or component of the affected system that is broken.
[ component: <tmpl_string> ]

# A cluster or grouping of sources.
[ group: <tmpl_string> ]

# The class/type of the event.
[ class: <tmpl_string> ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

# The maximum time to wait for a pagerduty request to complete, before failing the
# request and allowing it to be retried. The default value of 0s indicates that
# no timeout should be applied.
# NOTE: This will have no effect if set higher than the group_interval.
[ timeout: <duration> | default = 0s ]

<image_config> (PagerDuty)

這些欄位在 PagerDuty API 文件  中有詳細說明。

href: <tmpl_string>
src: <tmpl_string>
alt: <tmpl_string>

這些欄位在 PagerDuty API 文件  中有詳細說明。

href: <tmpl_string>
text: <tmpl_string>

<pushover_config>

Pushover 通知透過 Pushover API  傳送。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The recipient user's key.
# user_key and user_key_file are mutually exclusive.
user_key: <secret>
user_key_file: <filepath>

# Your registered application's API token, see https://pushover.net/apps
# You can also register a token by cloning this Prometheus app:
# https://pushover.net/apps/clone/prometheus
# token and token_file are mutually exclusive.
token: <secret>
token_file: <filepath>

# Notification title.
[ title: <tmpl_string> | default = '{{ template "pushover.default.title" . }}' ]

# Notification message.
[ message: <tmpl_string> | default = '{{ template "pushover.default.message" . }}' ]

# A supplementary URL shown alongside the message.
[ url: <tmpl_string> | default = '{{ template "pushover.default.url" . }}' ]

# Optional device to send notification to, see https://pushover.net/api#device
[ device: <string> ]

# Optional sound to use for notification, see https://pushover.net/api#sound
[ sound: <string> ]

# Priority, see https://pushover.net/api#priority
[ priority: <tmpl_string> | default = '{{ if eq .Status "firing" }}2{{ else }}0{{ end }}' ]

# How often the Pushover servers will send the same notification to the user.
# Must be at least 30 seconds.
[ retry: <duration> | default = 1m ]

# How long your notification will continue to be retried for, unless the user
# acknowledges the notification.
[ expire: <duration> | default = 1h ]

# Optional time to live (TTL) to use for notification, see https://pushover.net/api#ttl
[ ttl: <duration> ]

# Optional HTML/monospace formatting for the message, see https://pushover.net/api#html
# html and monospace formatting are mutually exclusive.
[ html: <boolean> | default = false ]
[ monospace: <boolean> | default = false ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<rocketchat_config>

Rocketchat 通知透過 Rocketchat REST API  傳送。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]
[ api_url: <string> | default = global.rocketchat_api_url ]
[ channel: <tmpl_string> | default = global.rocketchat_api_url ]

# The sender token and token_id
# See https://docs.rocket.chat/use-rocket.chat/user-guides/user-panel/my-account#personal-access-tokens
# token and token_file are mutually exclusive.
# token_id and token_id_file are mutually exclusive.
token: <secret>
token_file: <filepath>
token_id: <secret>
token_id_file: <filepath>


[ color: <tmpl_string | default '{{ if eq .Status "firing" }}red{{ else }}green{{ end }}' ]
[ emoji <tmpl_string | default = '{{ template "rocketchat.default.emoji" . }}'
[ icon_url <tmpl_string | default = '{{ template "rocketchat.default.iconurl" . }}'
[ text <tmpl_string | default = '{{ template "rocketchat.default.text" . }}'
[ title <tmpl_string | default = '{{ template "rocketchat.default.title" . }}'
[ title_link <tmpl_string | default = '{{ template "rocketchat.default.titlelink" . }}'
fields:
  [ <rocketchat_field_config> ... ]
[ image_url <tmpl_string> ]
[ thumb_url <tmpl_string> ]
[ link_names <tmpl_string> ]
[ short_fields: <boolean> | default = false ]
actions:
  [ <rocketchat_action_config> ... ]

<rocketchat_field_config>

這些欄位在 Rocketchat API 文件  中有詳細說明。

[ title: <tmpl_string> ]
[ value: <tmpl_string> ]
[ short: <boolean> | default = rocketchat_config.short_fields ]

<rocketchat_action_config>

這些欄位在 Rocketchat API 模型  中有詳細說明。

[ type: <tmpl_string> | ignored, only "button" is supported ]
[ text: <tmpl_string> ]
[ url: <tmpl_string> ]
[ msg: <tmpl_string> ]

<slack_config>

Slack 通知可以透過 傳入的 Webhook (Incoming webhooks) 機器人令牌 (Bot tokens)  傳送。

如果使用傳入的 webhook,則必須將 api_url 設定為傳入 webhook 的 URL,或者寫入 api_url_file 中引用的檔案。

如果使用機器人令牌,則必須將 api_url 設定為 https://slack.com/api/chat.postMessage,機器人令牌必須在 http_config 中設定為授權憑據,且 channel 必須包含要傳送通知的頻道名稱或頻道 ID。如果使用頻道名稱,開頭的 # 是可選的。

該通知包含一個 附件 (attachment) 

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = false ]
# The Slack webhook URL. Either api_url/api_url_file OR app_token/app_token_file should be set, but not both.
# Defaults to global settings if none are set here.
[ api_url: <secret> | default = global.slack_api_url ]
[ api_url_file: <filepath> | default = global.slack_api_url_file ]

# Slack App token for OAuth authentication. Mutually exclusive with api_url/api_url_file.
# Defaults to global settings if no local authorization or webhook URL is configured.
[ app_token: <secret> | default = global.slack_app_token ]
[ app_token_file: <filepath> | default = global.slack_app_token_file ]

# The Slack App URL. Required when using app_token authentication.
[ app_url: <string> | default = global.slack_app_url ]

# The channel or user to send notifications to.
channel: <tmpl_string>

# API request data as defined by the Slack webhook API.
[ icon_emoji: <tmpl_string> | default = '{{ template "slack.default.iconemoji" . }}' ]
[ icon_url: <tmpl_string> | default = '{{ template "slack.default.iconurl" . }}' ]
[ link_names: <boolean> | default = false ]
# The text content of the Slack message.
# If set, this is sent as the top-level 'text' field in the Slack payload.
# This is useful for simple notifications or compatibility with Slack Workflow Webhooks.
[ message_text: <tmpl_string> ]
[ username: <tmpl_string> | default = '{{ template "slack.default.username" . }}' ]
# The following parameters define the attachment.
actions:
  [ <action_config> ... ]
[ callback_id: <tmpl_string> | default = '{{ template "slack.default.callbackid" . }}' ]
[ color: <tmpl_string> | default = '{{ template "slack.default.color" . }}' ]
[ fallback: <tmpl_string> | default = '{{ template "slack.default.fallback" . }}' ]
fields:
  [ <field_config> ... ]
[ footer: <tmpl_string> | default = '{{ template "slack.default.footer" . }}' ]
[ mrkdwn_in: [ <string>, ... ] | default = ["fallback", "pretext", "text"] ]
[ pretext: <tmpl_string> | default = '{{ template "slack.default.pretext" . }}' ]
[ short_fields: <boolean> | default = false ]
[ text: <tmpl_string> | default = '{{ template "slack.default.text" . }}' ]
[ title: <tmpl_string> | default = '{{ template "slack.default.title" . }}' ]
[ title_link: <tmpl_string> | default = '{{ template "slack.default.titlelink" . }}' ]
[ image_url: <tmpl_string> ]
[ thumb_url: <tmpl_string> ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

# The maximum time to wait for a slack request to complete, before failing the
# request and allowing it to be retried. The default value of 0s indicates that
# no timeout should be applied.
# NOTE: This will have no effect if set higher than the group_interval.
[ timeout: <duration> | default = 0s ]

# Enables updating existing Slack messages instead of creating new ones on alert state change.
# Webhook URLs do not support updates.
[ update_message: <boolean> | default = false ]

<action_config> (Slack)

這些欄位在 Slack API 文件中關於 訊息附件 (message attachments) 互動式訊息 (interactive messages)  有詳細說明。

text: <tmpl_string>
type: <tmpl_string>
# Either url or name and value are mandatory.
[ url: <tmpl_string> ]
[ name: <tmpl_string> ]
[ value: <tmpl_string> ]

[ confirm: <action_confirm_field_config> ]
[ style: <tmpl_string> | default = '' ]
<action_confirm_field_config> (Slack)

這些欄位在 Slack API 文件  中有詳細說明。

text: <tmpl_string>
[ dismiss_text: <tmpl_string> | default '' ]
[ ok_text: <tmpl_string> | default '' ]
[ title: <tmpl_string> | default '' ]

<field_config> (Slack)

這些欄位在 Slack API 文件  中有詳細說明。

title: <tmpl_string>
value: <tmpl_string>
[ short: <boolean> | default = slack_config.short_fields ]

<sns_config>

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The SNS API URL i.e. https://sns.us-east-2.amazonaws.com.
#  If not specified, the SNS API URL from the SNS SDK will be used.
[ api_url: <tmpl_string> ]

# Configures AWS's Signature Verification 4 signing process to sign requests.
sigv4:
  [ <sigv4_config> ]

# SNS topic ARN, i.e. arn:aws:sns:us-east-2:698519295917:My-Topic
# If you don't specify this value, you must specify a value for the phone_number or target_arn.
# If you are using a FIFO SNS topic you should set a message group interval longer than 5 minutes
# to prevent messages with the same group key being deduplicated by the SNS default deduplication window
[ topic_arn: <tmpl_string> ]

# Subject line when the message is delivered to email endpoints.
[ subject: <tmpl_string> | default = '{{ template "sns.default.subject" .}}' ]

# Phone number if message is delivered via SMS in E.164 format.
# If you don't specify this value, you must specify a value for the topic_arn or target_arn.
[ phone_number: <tmpl_string> ]

# The  mobile platform endpoint ARN if message is delivered via mobile notifications.
# If you don't specify this value, you must specify a value for the topic_arn or phone_number.
[ target_arn: <tmpl_string> ]

# The message content of the SNS notification.
[ message: <tmpl_string> | default = '{{ template "sns.default.message" .}}' ]

# SNS message attributes.
attributes:
  [ <string>: <string> ... ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

# Force the AWS SDK's HTTP client (BuildableClient) instead of the default
# tracing-wrapped client. Required when the AWS SDK needs to inject a custom
# CA bundle (e.g. via `ca_bundle` in the AWS shared config). Auto-enabled
# when the AWS_CA_BUNDLE environment variable is set.
#
# When this flag is set tracing is disabled for SNS requests, and only the
# `tls_config` and proxy fields of `http_config` are honored. Other
# `http_config` knobs (basic_auth, oauth2, authorization, follow_redirects,
# enable_http2, http_headers) are silently ignored — most are irrelevant for
# AWS calls (which use SigV4) but if you depend on them for SNS, do not enable
# this.
[ use_aws_http_client: <boolean> | default = false ]

<sigv4_config> (SNS)

# The AWS region. If blank, the region from the default credentials chain is used.
[ region: <string> ]

# The AWS API keys. Both access_key and secret_key must be supplied or both must be blank.
# If blank the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are used.
[ access_key: <string> ]
[ secret_key: <secret> ]

# Named AWS profile used to authenticate.
[ profile: <string> ]

# AWS Role ARN, an alternative to using AWS API keys.
[ role_arn: <string> ]

<telegram_config>

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The Telegram API URL i.e. https://api.telegram.org.
# If not specified, default API URL will be used.
[ api_url: <string> | default = global.telegram_api_url ]

# Telegram bot token. It is mutually exclusive with `bot_token_file`.
[ bot_token: <secret> ]

# Read the Telegram bot token from a file. It is mutually exclusive with `bot_token`.
[ bot_token_file: <filepath> ]

# ID of the chat where to send the messages. It is mutually exclusive with `chat_id_file`.
[ chat_id: <int> ]

# Read the chat ID from a file. It is mutually exclusive with `chat_id`.
[ chat_id_file: <filepath> ]

# Optional ID of the message thread where to send the messages.
[ message_thread_id: <int> ]

# Message template.
[ message: <tmpl_string> default = '{{ template "telegram.default.message" .}}' ]

# Disable telegram notifications
[ disable_notifications: <boolean> | default = false ]

# Parse mode for telegram message, supported values are MarkdownV2, Markdown, HTML and empty string for plain text.
# If the message exceeds Telegram's character limit, it will be truncated or replaced with a fallback message if parse_mode is set to HTML.
[ parse_mode: <string> | default = "HTML" ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<victorops_config>

VictorOps 通知透過 VictorOps API  傳送

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The API key to use when talking to the VictorOps API.
# It is mutually exclusive with `api_key_file`.
[ api_key: <secret> | default = global.victorops_api_key ]

# Reads the API key to use when talking to the VictorOps API from a file.
# It is mutually exclusive with `api_key`.
[ api_key_file: <filepath> | default = global.victorops_api_key_file ]

# The VictorOps API URL.
[ api_url: <string> | default = global.victorops_api_url ]

# A key used to map the alert to a team.
routing_key: <tmpl_string>

# Describes the behavior of the alert (CRITICAL, WARNING, INFO).
[ message_type: <tmpl_string> | default = 'CRITICAL' ]

# Contains summary of the alerted problem.
[ entity_display_name: <tmpl_string> | default = '{{ template "victorops.default.entity_display_name" . }}' ]

# Contains long explanation of the alerted problem.
[ state_message: <tmpl_string> | default = '{{ template "victorops.default.state_message" . }}' ]

# The monitoring tool the state message is from.
[ monitoring_tool: <tmpl_string> | default = '{{ template "victorops.default.monitoring_tool" . }}' ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

<webhook_config>

webhook 接收器允許配置一個通用接收器。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The endpoint to send HTTP POST requests to.
# url and url_file are mutually exclusive.
url: <secret>
url_file: <filepath>

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

# The maximum number of alerts to include in a single webhook message. Alerts
# above this threshold are truncated. When leaving this at its default value of
# 0, all alerts are included.
[ max_alerts: <int> | default = 0 ]

# The maximum time to wait for a webhook request to complete, before failing the
# request and allowing it to be retried. The default value of 0s indicates that
# no timeout should be applied.
# NOTE: This will have no effect if set higher than the group_interval.
[ timeout: <duration> | default = 0s ]

# Define custom payload to be sent to the webhook endpoint.
# USE AT YOUR OWN RISK: This is an advanced configuration option that allows you
# to define a custom payload using Go templates. Be aware that the Alertmanager does not
# perform any validation on the resulting payload, and it is your responsibility to
# ensure that the generated payload is in the desired format expected by the receiving endpoint.
# The payload has to be valid JSON. You can use the `toJson` function to help with this.
# THE ALERTMANAGER TEAM WILL NOT PROVIDE ANY SUPPORT FOR ISSUES ARISING FROM THE USE OF THIS OPTION.
[ payload: { <string>: <tmpl_string>, ... } ]

Alertmanager 將向配置的端點發送以下 JSON 格式的 HTTP POST 請求

{
  "version": "4",
  "groupKey": <string>,              // key identifying the group of alerts (e.g. to deduplicate)
  "truncatedAlerts": <int>,          // how many alerts have been truncated due to "max_alerts"
  "status": "<resolved|firing>",
  "receiver": <string>,
  "groupLabels": <object>,
  "commonLabels": <object>,
  "commonAnnotations": <object>,
  "externalURL": <string>,           // backlink to the Alertmanager.
  "alerts": [
    {
      "status": "<resolved|firing>",
      "labels": <object>,
      "annotations": <object>,
      "startsAt": "<rfc3339>",
      "endsAt": "<rfc3339>",
      "generatorURL": <string>,      // identifies the entity that caused the alert
      "fingerprint": <string>        // fingerprint to identify the alert
    },
    ...
  ]
}

這裡有一個具有此功能的 整合 列表。

<incidentio_config>

incident.io 通知透過 incident.io 告警源 API  傳送。

配置此整合時,您可以透過 http_config 直接設定 authorization,也可以使用 alert_source_tokenalert_source_token_file 之一。alert_source_tokenalert_source_token_file 的配置優先順序高於 http_config

請注意,如果有效載荷(payload)超過 incident.io 的 API 限制 (512KB),該整合將自動截斷除第一個告警以外的所有告警。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]

# The URL to send the incident.io alert. This would typically be provided by the
# incident.io team when setting up an alert source.
# URL and URL_file are mutually exclusive.
url: <string>
url_file: <filepath>

# The alert source token is used to authenticate with incident.io.
# alert_source_token and alert_source_token_file are mutually exclusive.
[ alert_source_token: <secret> ]
[ alert_source_token_file: <filepath> ]

# The maximum number of alerts to be sent per incident.io message.
# Alerts exceeding this threshold will be truncated. Setting this to 0
# allows an unlimited number of alerts. Note that if the payload exceeds
# incident.io's size limits (512KB), the notifier will automatically drop
# all alerts except the first one. If the payload is still too
# large after this truncation, you will receive a 429 response and alerts
# will not be ingested.
[ max_alerts: <int> | default = 0 ]

# Timeout is the maximum time allowed to invoke incident.io. Setting this to 0
# does not impose a timeout.
[ timeout: <duration> | default = 0s ]

<wechat_config>

微信通知透過 微信 API  傳送。

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = false ]

# The API key to use when talking to the WeChat API. Either api_secret or api_secret_file should be set.
[ api_secret: <secret> | default = global.wechat_api_secret ]
[ api_secret_file: <string> | default = global.wechat_api_secret_file ]

# The WeChat API URL.
[ api_url: <string> | default = global.wechat_api_url ]

# The corp id for authentication.
[ corp_id: <string> | default = global.wechat_api_corp_id ]

# API request data as defined by the WeChat API.
[ message: <tmpl_string> | default = '{{ template "wechat.default.message" . }}' ]
# Type of the message type, supported values are `text` and `markdown`.
[ message_type: <string> | default = 'text' ]
[ agent_id: <string> | default = '{{ template "wechat.default.agent_id" . }}' ]
[ to_user: <string> | default = '{{ template "wechat.default.to_user" . }}' ]
[ to_party: <string> | default = '{{ template "wechat.default.to_party" . }}' ]
[ to_tag: <string> | default = '{{ template "wechat.default.to_tag" . }}' ]

<webex_config>

# Whether to notify about resolved alerts.
[ send_resolved: <boolean> | default = true ]

# The Webex Teams API URL i.e. https://webexapis.com/v1/messages
# If not specified, default API URL will be used.
[ api_url: <string> | default = global.webex_api_url ]

# ID of the Webex Teams room where to send the messages.
room_id: <tmpl_string>

# Message template.
[ message: <tmpl_string> default = '{{ template "webex.default.message" .}}' ]

# The HTTP client's configuration. You must use this configuration to supply the bot token as part of the HTTP `Authorization` header.
[ http_config: <http_config> | default = global.http_config ]

追蹤配置

<tracing_config>

# The tracing client type, supported values are `http` and `grpc`.
[ client_type: <tracing_client_type> | default = "grpc" ]

# The tracing endpoint.
[ endpoint: <string> | default = "" ]

# The sampling fraction.
[ sampling_fraction: <float> | default = 0.0 ]

# Whether to disable TLS.
[ insecure: <boolean> | default = false ]

# The HTTP client's configuration.
[ tls_config: <tls_config> ]

# Custom HTTP headers.
[ http_headers:
  [ <http_header> ] ]

# The tracing compression.
[ compression: <string> | default = "gzip" ]

# The tracing timeout.
[ timeout: <duration> | default = 0s ]

事件記錄器

事件記錄器捕獲重要的 Alertmanager 事件(程序啟動和關閉、告警生命週期轉換、靜默建立、通知傳送以及靜音/抑制機制),並將它們分發到一個或多個目的地。每個事件都編碼為包含時間戳、生成例項的主機名、叢集位置(啟用 HA 叢集時)以及事件特定資料的結構化有效載荷。

該記錄器受 event-recorder 功能標誌保護 — 請在命令列中傳遞 --enable-feature=event-recorder 來啟用它。未設定該標誌時,記錄器將靜默丟棄所有事件。

事件記錄在頂層 event_recorder 鍵下進行配置。

<event_recorder_config>

輸出按型別分組,每個目的地型別一個列表(類似於接收器分組其整合的方式)。每個記錄的事件都會發送到所有列表中的每個輸出。

# JSONL file outputs.
file_outputs:
  [ - <file_output> ... ]

# Webhook outputs.
webhook_outputs:
  [ - <webhook_output> ... ]

# Kafka outputs.
kafka_outputs:
  [ - <kafka_output> ... ]

<file_output>

將每個事件作為單行 JSON 寫入檔案。當父目錄觀察到目標路徑上發生重新命名/刪除/建立時,該檔案將被重新開啟(以便與 logrotate 和類似工具相容)。

# Path to the JSONL output file.  Will be created if it does not exist.
path: <filepath>

<webhook_output>

將每個事件作為 JSON 主體以 POST 方式傳送到 HTTP 端點。交付由一個具有有界重試和指數退避的有界工作執行緒池執行。

# URL to POST events to.
url: <secret>

# HTTP client configuration (TLS, basic auth, OAuth, proxies, ...).
[ http_config: <http_config> ]

# HTTP request timeout.
[ timeout: <duration> | default = 10s ]

# Number of concurrent delivery workers.
[ workers: <int> | default = 4 ]

# Maximum number of delivery attempts per event.
[ max_retries: <int> | default = 3 ]

# Base backoff between retries; subsequent attempts use exponential
# backoff (base * 2^attempt) capped at 30s.
[ retry_backoff: <duration> | default = 500ms ]

<kafka_output>

將每個事件生成到 Kafka 主題中。記錄使用生成該事件的 Alertmanager 例項的主機名作為訊息鍵,這可將單個例項的所有事件保留在同一個分割槽上,並保留其相對順序。交付是非同步且有界的:當本地緩衝區滿時,事件將被丟棄。

啟動時無法連線到 Kafka 代理會被記錄在 warn 級別,但不會阻止 Alertmanager 啟動;底層客戶端將在後臺重試連線。

目標主題必須已經存在(或代理必須配置為自動建立主題);Alertmanager 不會建立它。

# Seed broker list (host:port).  At least one entry is required.
brokers:
  [ - <string> ... ]

# Topic to produce events to.
topic: <string>

# Client identifier reported to the brokers.
[ client_id: <string> | default = "alertmanager" ]

# On-the-wire encoding for each record value: "json" (protojson) or
# "protobuf" (binary proto).  JSON is the default for symmetry with the
# file and webhook outputs; consumers that already use the
# eventrecorder.proto schema may prefer protobuf for compactness.
[ format: <"json" | "protobuf"> | default = "json" ]

# Producer acknowledgement level.  "leader" matches the franz-go default
# and minimizes Alertmanager's exposure to Kafka latency.  "all" enables
# the idempotent producer for at-least-once durability at the cost of
# higher latency.
[ acks: <"none" | "leader" | "all"> | default = "leader" ]

# Compression codec for record batches.  When omitted, batches are sent
# uncompressed.
[ compression: <"none" | "gzip" | "snappy" | "lz4" | "zstd"> ]

# Capacity of the local buffer between the event recorder and franz-go.
# Events are dropped when this buffer is full.
[ buffer_size: <int> | default = 1024 ]

# TLS configuration for the broker connection.  When unset, the
# connection uses PLAINTEXT.
[ tls_config: <tls_config> ]

本頁內容