5.4. 配置警报通知
在 OpenShift Container Platform 4.20 中,您可以在 Alerting UI 中查看触发警报。您可以通过配置警报接收器,将 Alertmanager 配置为发送有关默认平台警报的通知。
Alertmanager 默认不会发送通知。强烈建议您通过 web 控制台或通过 alertmanager-main secret 配置警报接收器来接收通知。
5.4.1. 为默认平台警报配置警报路由 复制链接链接已复制到粘贴板!
您可以将 Alertmanager 配置为发送通知,以接收来自集群的重要警报。通过编辑 openshift-monitoring 命名空间中的 alertmanager-main secret 中的默认配置来自定义 Alertmanager 如何发送通知有关默认平台警报的通知。
OpenShift Container Platform Alertmanager 配置中也支持支持上游 Alertmanager 的所有功能。要检查受支持的上游 Alertmanager 版本的所有配置选项,请参阅 Alertmanager 配置 (Prometheus 文档)。
先决条件
-
您可以使用具有
cluster-admin集群角色的用户身份访问集群。 -
已安装 OpenShift CLI(
oc)。
流程
从
alertmanager-mainsecret 中提取当前活跃的 Alertmanager 配置,并将其保存为本地alertmanager.yaml文件:$ oc -n openshift-monitoring get secret alertmanager-main --template='{{ index .data "alertmanager.yaml" }}' | base64 --decode > alertmanager.yaml-
打开
alertmanager.yaml文件。 编辑 Alertmanager 配置:
可选:更改默认的 Alertmanager 配置:
默认 Alertmanager secret YAML 示例
global: resolve_timeout: 5m http_config: proxy_from_environment: true1 route: group_wait: 30s2 group_interval: 5m3 repeat_interval: 12h4 receiver: default routes: - matchers: - "alertname=Watchdog" repeat_interval: 2m receiver: watchdog receivers: - name: default - name: watchdog添加警报接收器配置:
# ... receivers: - name: default - name: watchdog - name: <receiver>1 <receiver_configuration>2 # ...将 PagerDuty 配置为警报接收器示例
# ... receivers: - name: default - name: watchdog - name: team-frontend-page pagerduty_configs: - routing_key: xxxxxxxxxx1 http_config:2 proxy_from_environment: true authorization: credentials: xxxxxxxxxx # ...将电子邮件配置为警报接收器示例
# ... receivers: - name: default - name: watchdog - name: team-frontend-page email_configs: - to: myemail@example.com1 from: alertmanager@example.com2 smarthost: 'smtp.example.com:587'3 auth_username: alertmanager@example.com4 auth_password: password hello: alertmanager5 # ...重要Alertmanager 需要外部 SMTP 服务器来发送电子邮件警报。要配置电子邮件警报接收器,请确保您具有外部 SMTP 服务器所需的连接详情。
添加路由配置:
# ... route: group_wait: 30s group_interval: 5m repeat_interval: 12h receiver: default routes: - matchers: - "alertname=Watchdog" repeat_interval: 2m receiver: watchdog - matchers:1 - "<your_matching_rules>"2 receiver: <receiver>3 # ...警告不要使用
match,match_re,target_match,target_match_re,source_match, 和source_match_re键名称,它们已弃用,并计划在以后的发行版本中删除。警报路由示例
# ... route: group_wait: 30s group_interval: 5m repeat_interval: 12h receiver: default routes: - matchers: - "alertname=Watchdog" repeat_interval: 2m receiver: watchdog - matchers:1 - "service=example-app" routes:2 - matchers: - "severity=critical" receiver: team-frontend-page # ...前面的示例将由
example-app服务触发的critica严重性的警报路由到team-frontend-page接收器。通常,这些类型的警报会传给个人或关键响应团队。
应用文件中的新配置:
$ oc -n openshift-monitoring create secret generic alertmanager-main --from-file=alertmanager.yaml --dry-run=client -o=yaml | oc -n openshift-monitoring replace secret --filename=-
验证
通过视觉化路由树来验证路由配置:
$ oc exec alertmanager-main-0 -n openshift-monitoring -- amtool config routes show --alertmanager.url http://localhost:9093输出示例
Routing tree: . └── default-route receiver: default ├── {alertname="Watchdog"} receiver: Watchdog └── {service="example-app"} receiver: default └── {severity="critical"} receiver: team-frontend-page
5.4.2. 使用 OpenShift Container Platform Web 控制台配置警报路由 复制链接链接已复制到粘贴板!
您可以通过 OpenShift Container Platform Web 控制台配置警报路由,以确保了解集群出现的重要问题。
OpenShift Container Platform Web 控制台提供比 alertmanager-main secret 配置警报路由的设置更少。要通过访问更多配置设置配置警报路由,请参阅"配置默认平台警报的警报路由"。
先决条件
-
您可以使用具有
cluster-admin集群角色的用户身份访问集群。
流程
在 OpenShift Container Platform web 控制台中,进入 Administration
Cluster Settings Configuration Alertmanager。 注意或者,您还可以通过 notification drawer 访问同一页面。选择 OpenShift Container Platform Web 控制台右上角的铃铛图标,并在 AlertmanagerReceiverNotConfigured 警报中选择 Configure。
- 在页面的 Receivers 部分中,点 Create Receiver。
- 在 Create Receiver 表单中,添加 Receiver Name,然后从列表中选择 Receiver Type。
编辑接收器配置:
对于 PagerDuty 接收器:
- 选择集成类型并添加 PagerDuty 集成密钥。
- 添加 PagerDuty 安装的 URL。
- 如果要编辑客户端和事件详情或严重性规格,请点 Show advanced configuration。
对于 Webhook 接收器:
- 添加将 HTTP POST 请求发送到的端点。
- 如果要编辑将已解析的警报发送给接收器的默认选项,请点 Show advanced configuration。
对于电子邮件接收器:
- 添加要将通知发送到的电子邮件地址。
添加 SMTP 配置详情,包括发送通知的地址、用来发送电子邮件的智能主机和端口号、SMTP 服务器的主机名以及验证详情。
重要Alertmanager 需要外部 SMTP 服务器来发送电子邮件警报。要配置电子邮件警报接收器,请确保您具有外部 SMTP 服务器所需的连接详情。
- 选择是否需要 TLS。
- 如果要将默认选项编辑为不向接收器发送已解析的警报,或编辑电子邮件通知正文配置,请点 Show advanced configuration。
对于 Slack 接收器:
- 添加 Slack Webhook 的 URL。
- 添加要将通知发送到的 Slack 频道或用户名。
- 如果要将默认选项编辑为不向接收器发送已解析的警报,或编辑图标和用户名配置,请选择 Show advanced configuration。您还可以选择是否查找并链接频道名称和用户名。
默认情况下,如果触发的警报带有与所有选择器匹配的标签,将被发送到接收器。如果您希望触发的警报在发送到接收器前完全匹配的标签值,请执行以下步骤:
- 在表单的 Routing Labels 部分中添加路由标签名称和值。
- 点 Add label 来添加更多路由标签。
- 点 Create 创建接收器。
5.4.3. 为默认平台警报和用户定义的警报配置不同的警报接收器 复制链接链接已复制到粘贴板!
您可以为默认平台警报和用户定义的警报配置不同的警报接收器,以确保以下结果:
- 所有默认平台警报都发送到团队拥有的接收器,以收取这些警报。
- 所有用户定义的警报都发送到另一个接收器,以便团队只能专注于平台警报。
您可以使用 Cluster Monitoring Operator 添加到所有平台警报的 openshift_io_alert_source="platform" 标签来实现此目的:
-
使用
openshift_io_alert_source="platform"matcher 来匹配默认平台警报。 -
使用
openshift_io_alert_source!="platform"或'openshift_io_alert_source=""匹配程序来匹配用户定义的警报。
如果您启用了专用于用户定义的警报的 Alertmanager 实例,则此配置不适用。