為 Prometheus 快訊設定簡易郵件傳輸通訊協定 (SMTP) 通知管道

本頁面說明如何設定及設定 Prometheus 警報的簡單郵件傳輸通訊協定 (SMTP) 通知管道。如果選擇不設定這個通知管道,您仍可在 infra-obs 或 platform-obs 中查看快訊。

請按照下列步驟設定 Slack 或電子郵件通知管道:

  1. 如要建立自訂快訊通知管道,請在網路中代管 SMTP 伺服器,並準備好 SMTP 設定詳細資料 (IP、使用者名稱、密碼、收件者電子郵件),以便建立 Alertmanager 設定。您可以從 bm03 ping SMTP 主機 IP,驗證 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_NAMEConfigMap 物件中設定檔的名稱必須與 ConfigMap 物件的名稱完全一致。舉例來說,如果您在步驟 2 中使用 appl-alert-notification 做為 ConfigMap 名稱,請在 ObservabilityPipeline 物件中為設定檔使用相同名稱。

  6. 將命名空間更新為上一步使用的值。

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

  8. 如果 GDC 的 Grafana 資訊主頁上顯示的快訊處於 firing 狀態,系統就會觸發電子郵件通知。啟動您在先前步驟中使用的命名空間的 Grafana,並檢查 firing 狀態的快訊。系統會將快訊傳送至你的電子郵件地址。