一、如何使用自定义配置文件
启动时指定alertmanager的配置文件
./alertmanager --config.file=alertmanager.yml
配置项说明
<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>:模板的密钥
<int>:整数值
全局配置简要说明
global:
[ smtp_from: <tmpl_string> ]
# 从一个模板字符串中获取相关SMTP配置,样例: smtp.example.org:587
[ smtp_smarthost: <string> ]
# 提供给smtp服务器的默认hostName.
[ smtp_hello: <string> | default = "localhost" ]
# SMTP 使用 CRAM-MD5\LOGIN\PLAIN进行身份验证. 如果为空,Alertmanager不会对SMTP服务器进行身份验证。
[ 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.
# Note that Go does not support unencrypted connections to remote SMTP endpoints.
[ 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/" ]
[ 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> ]
# 告警解决超时时间,超过这个时间时会被认为已解决,默认5分钟.
[ resolve_timeout: <duration> | default = 5m ]
# 客户化模板列表
templates:
[ - <filepath> ... ]
# 路由配置根节点
route: <route>
# 通知接收器列表
receivers:
- <receiver> ...
# 通知抑制规则列表.
inhibit_rules:
[ - <inhibit_rule> ... ]
二、路由配置说明
[ receiver: <string> ]
# 路由接收器名称,用于匹配接收器
# 根据标签进行告警分组。
[ group_by: '[' <labelname>, ... ']' ]
# 报警是否应该继续匹配同级节点,默认不继续匹配.
[ continue: <boolean> | default = false ]
# 使用标签匹配报警,必须包含指定标签才匹配。
match:
[ <labelname>: <labelvalue>, ... ]
# 是否正则表达式的值来匹配标签值。
match_re:
[ <labelname>: <regex>, ... ]
# 告警组等待时间。
[ group_wait: <duration> | default = 30s ]
# 新告警产生时,等待多久增加到已发送的告警内容中并发送。
[ group_interval: <duration> | default = 5m ]
# 重复发送告警时间间隔
[ repeat_interval: <duration> | default = 4h ]
# 特定的路由
routes:
[ - <route> ... ]
三、接收器receiver配置说明
webhook配置说明
# 是否发送解决告警信息
[ send_resolved: <boolean> | default = true ]
# webhook地址
url: <string>
# http请求客户端配置。默认使用全局配资
[ http_config: <http_config> | default = global.http_config ]
# 最大的告警记录数,默认0表示所有数据
[ max_alerts: <int> | default = 0 ]
限制接收器告警条数
只需要配置max_alerts: int 即可,int为最大记录数。
email配置说明
# 是否发送解决信息
[ send_resolved: <boolean> | default = false ]
# 目标邮箱
to: <tmpl_string>
# 发件人邮箱,默认取全局配置.
[ 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_username: <string> | default = global.smtp_auth_username ]
[ auth_password: <secret> | default = global.smtp_auth_password ]
[ auth_secret: <secret> | default = global.smtp_auth_secret ]
[ 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 ]
# TLS configuration.
tls_config:
[ <tls_config> ]
# HTML格式的邮件模板
[ html: <tmpl_string> | default = '{{ template "email.default.html" . }}' ]
# TEXT格式的邮件模板
[ text: <tmpl_string> ]
# Further headers email header key/value pairs. Overrides any headers
# previously set by the notification implementation.
[ headers: { <string>: <tmpl_string>, ... } ]