【问题标题】:How do I tell Prometheus' Alertmanager to send email through Gmail's SMTP server如何告诉 Prometheus 的 Alertmanager 通过 Gmail 的 SMTP 服务器发送电子邮件
【发布时间】:2016-06-08 19:57:06
【问题描述】:

我希望 Prometheus 在指标超过特定阈值时从 Gmail (Gapps) 帐户发送电子邮件。 在Alertmanager config docs 中,没有提到密码。如何对 SMTP 服务器进行身份验证?

【问题讨论】:

    标签: smtp gmail smtp-auth prometheus


    【解决方案1】:

    这可以通过配置文件中的auth_usernameauth_passwordauth_identity 字段来完成。

    http://www.robustperception.io/sending-email-with-the-alertmanager-via-gmail/ 有完整指南

    确保您使用的是最新的警报管理器,0.1.1 将无法工作。

    【讨论】:

    • 我认为肯定还有更多需要。电子邮件通知仍然失败并出现错误“必须先发出 STARTTLS 命令”
    • 为了进一步澄清阅读此问题的任何人 - 在编写此问题时,Prometheus 代码中存在一个错误,该错误阻止了电子邮件警报与 TLS 服务器一起使用。 - 在发表此评论时,有一个已提交给 github 存储库的修复程序,但还没有包含该修复程序的版本。目前,必须从源代码构建 Prometheus 才能通过 gmail(或其他需要 TLS 的 SMTP 主机)使用电子邮件警报。
    • 还要注意配置的位置已经改变,它现在在配置文件而不是环境变量中。该指南已更新,但尚未发布。
    • @brian-brazil 该配置在 2018 年仍然正确吗?
    • @ipeacocks,是的,刚刚测试过,这仍然有效。我想note,将环境变量用于机密信息(例如应用程序密码/令牌)是违反最佳实践的。 @brian-brazil 的文章将在编写配置时更改变量。
    【解决方案2】:

    您可以在警报管理器配置文件中使用以下模板,并根据您的要求更改值。

    config:
      global:
        resolve_timeout: 5m
      route:
        group_by: ['job']
        group_wait: 30s
        group_interval: 5m
        repeat_interval: 1h
        receiver: 'tech-email'
        routes:
        - match:
            alertname: Watchdog
          receiver: 'null'
      receivers:
      - name: 'tech-email'
        email_configs:
        - to: 'to-email@example.com'
          from: 'from-email@outlook.com'
          auth_username: **********
          auth_password: **********
          require_tls: yes
          smarthost: **********
          send_resolved: true
      - name: 'null'
    

    对于 auth_usernameauth_passwordsmarthost,您可以从 SES 或任何提供商生成凭据。

    【讨论】:

      猜你喜欢
      • 2022-01-09
      • 2013-03-13
      • 2014-10-15
      • 1970-01-01
      • 2018-10-17
      • 2016-09-07
      • 2016-02-09
      相关资源
      最近更新 更多