Alertmanager通过命令行标志和配置文件进行配置。 虽然命令行标志配置了不可变的系统参数,但配置文件定义了禁止规则,通知路由和通知接收器。
可视化编辑器可以帮助构建路由树。
要查看所有可用的命令行标志,请运行alertmanager -h
。
Alertmanager可以在运行时重新加载其配置。 如果新配置格式不正确,则不会应用更改并记录错误。 通过向进程发送SIGHUP
或向/-/reload
端点发送HTTP POST请求来触发配置重新加载。
一、配置文件
指定要加载的配置文件,使用--config.file
标志
./alertmanager --config.file=simple.yml
该文件以YAML格式写入,由下面描述的方案定义。括号表示参数是可选的。对于非列表参数,该值设置为指定的默认值。
通用占位符定义如下:
<duration>
:与正则表达式匹配的持续时间[0-9]+(ms|[smhdwy])
<labelname>
:与正则表达式匹配的字符串[a-zA-Z _][a-zA-Z0-9 _]*
<labelvalue>
:一串unicode字符<filepath>
:当前工作目录中的有效路径<boolean>
:一个可以取值为true
或false
的布尔值<string>
:常规字符串<secret>
:一个秘密的常规字符串,例如密码<tmpl_string>
:在使用前进行模板扩展的字符串<tmpl_secret>
:在使用之前进行模板扩展的字符串,它是一个秘密
其他占位符是单独指定的。
可以在此处找到有效的示例文件。
全局配置指定在所有其他配置上下文中有效的参数。它们还可用作其他配置节的默认值。
global:
# ResolveTimeout is the time after which an alert is declared resolved
# if it has not been updated.
[ resolve_timeout: <duration> | default = 5m ]
# 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_username: <string> ]
# SMTP Auth using LOGIN and PLAIN.
[ smtp_auth_password: <secret> ]
# SMTP Auth using PLAIN.
[ smtp_auth_identity: <string> ]
# SMTP Auth using CRAM-MD5.
[ smtp_auth_secret: <secret> ]
# The default SMTP TLS requirement.
[ smtp_require_tls: <bool> | default = true ]
# The API URL to use for Slack notifications.
[ slack_api_url: <secret> ]
[ victorops_api_key: <secret> ]
[ 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_url: <string> | default = "https://api.opsgenie.com/" ]
[ hipchat_api_url: <string> | default = "https://api.hipchat.com/" ]
[ hipchat_auth_token: <secret> ]
[ wechat_api_url: <string> | default = "https://qyapi.weixin.qq.com/cgi-bin/" ]
[ wechat_api_secret: <secret> ]
[ wechat_api_corp_id: <string> ]
# The default HTTP client configuration
[ http_config: <http_config> ]
# 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> ... ]
二、<route>
路由块定义路由树中的节点及其子节点。 如果未设置,则其可选配置参数将从其父节点继承。
每个警报都在配置的顶级路由中进入路由树,该路由必须匹配所有警报(即没有任何已配置的匹配器)。 然后它遍历子节点。 如果将continue
设置为false,则在第一个匹配的子项后停止。 如果匹配节点上的continue
为true,则警报将继续与后续兄弟节点匹配。 如果警报与节点的任何子节点都不匹配(没有匹配的子节点,或者不存在),则根据当前节点的配置参数处理警报。
[ 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 ]
# A set of equality matchers an alert has to fulfill to match the node.
match:
[ <labelname>: <labelvalue>, ... ]
# A set of regex-matchers an alert has to fulfill to match the node.
match_re:
[ <labelname>: <regex>, ... ]
# How long to initially wait to send a notification for a group
# of al