为 Prometheus 提醒配置简单邮件传输协议 (SMTP) 通知渠道

本页介绍如何为 Prometheus 提醒设置和配置简单邮件传输协议 (SMTP) 通知渠道。如果您选择不设置此通知渠道,仍然可以在 infra-obs 或 platform-obs 中查看提醒。

请按以下步骤操作,配置 Slack 或电子邮件通知渠道:

  1. 如需创建自定义提醒通知渠道,请在您的网络中托管 SMTP 服务器,并准备好 SMTP 配置详细信息(IP、用户名、密码、接收者电子邮件地址),以便创建 Alertmanager 配置。您可以从 bm03 中 ping SMTP 主机 IP,以验证其正确性。

  2. 创建一个包含以下内容的 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**
    
  3. 使用正确的内容更新必填字段。

  4. 运行 kubectl apply -f cm.yaml

  5. 创建具有以下内容的 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 对象中为配置文件使用相同的名称。

  6. 将命名空间更新为上一步中使用的值。

  7. 运行 kubectl apply -f ob.yaml.

  8. 如果 GDC 的 Grafana 信息中心上显示的所有提醒处于 firing 状态,则会触发电子邮件。针对您在前面步骤中使用的命名空间启动 Grafana,并检查是否存在处于 firing 状态的提醒。提醒会发送到您的电子邮件地址。