借助 Google Distributed Cloud (GDC) 网闸隔离设备中的简单邮件传输协议 (SMTP) 通知渠道,您可以通过 ObservabilityPipeline 自定义资源将触发的 Prometheus 提醒直接发送到团队的电子邮件。如果您选择不配置电子邮件通知,则仍可以在 infra-obs 和 platform-obs 命名空间的 Grafana 信息中心内查看提醒。
准备工作
配置通知渠道
请按照以下步骤配置 Slack 或电子邮件通知渠道:
如需创建自定义提醒通知渠道,请在您的网络中托管 SMTP 服务器,并准备好 SMTP 配置详细信息(IP、用户名、密码、接收者电子邮件地址),以便创建 alertmanager 配置。您可以通过从 bm03 对 SMTP 主机 IP 执行 ping 操作来验证其正确性。
创建一个包含以下内容的
cm.yml文件。smtp_smarthost必须具有客户托管的 SMTP 服务器的 IP 地址。apiVersion: v1 kind: ConfigMap metadata: # The name must match the ConfigMap name specified in the ObservabilityPipeline custom resource. name: appl-alert-notification # The namespace must match the project namespace namespace: PROJECT_NAMESPACE data: # The file name must be alertmanager.yml alertmanager.yml: | global: smtp_smarthost: SMTP HOST IP ADDRESS smtp_from: FROM_EMAIL_ADDRESS # Give empty string for unsecured smtp server in username and password and false in smtp_require_tls. smtp_auth_username: USERNAME smtp_auth_password: PASSWORD smtp_require_tls: true route: group_by: ['alertname', 'cluster', 'service'] group_wait: 30s group_interval: 5m repeat_interval: 3h receiver: team-X-mails receivers: - name: 'team-X-mails' email_configs: - to: **RECIEVER_EMAIL_ID**使用正确的内容更新必填字段。
运行
kubectl apply -f cm.yaml。创建包含以下内容的
ObservabilityPipeline自定义资源:# Configure observability pipeline apiVersion: observability.gdc.goog/v1 kind: ObservabilityPipeline metadata: # Choose namespace that matches the project's namespace namespace: PROJECT_NAMESPACE name: observability-config spec: # Configure Alertmanager alerting: # Permission: PA and AO # The alerts configuration must be in the key "alertmanager.yml" of the configMap alertmanagerConfig: CUSTOMIZED_CONFIGMAP_NAME ...替换以下内容:
- PROJECT_NAMESPACE:项目的命名空间。
CUSTOMIZED_CONFIGMAP_NAME:您在
ConfigMap对象中为配置文件使用的名称必须与ConfigMap对象的名称完全一致。例如,在第 2 步中,如果您使用appl-alert-notification作为ConfigMap名称,则在ObservabilityPipeline对象中为配置文件使用相同的名称。
将命名空间更新为上一步中使用的值。
运行
kubectl apply -f ob.yaml.如果 GDC 的 Grafana 信息中心内显示的所有提醒处于
firing状态,则会触发电子邮件。为之前步骤中使用的命名空间启动 Grafana,并检查处于firing状态的提醒。提醒会发送到您的邮箱。