0

我正在grafana/grafana:6.1.3prom/alertmanager:v0.16.2(以及我认为其他一些不相关的图像)结合使用。
如果发生特定事件,我将警报管理器配置为通过 SMTP 发送电子邮件。
但是我的收件箱里什么都没有,这就是我查看 grafana docker 日志的原因:

root@PRIVATE_INFORMATION:~# docker logs grafana | grep -n "alert"
162:t=2019-05-20T11:42:26+0000 lvl=info msg="Executing migration" logger=migrator id="create alert table v1"
[...]
197:t=2019-05-20T11:42:28+0000 lvl=info msg="Executing migration" logger=migrator id="Update alert annotations and set TEXT to empty"
292:t=2019-05-20T11:44:28+0000 lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/api/alerts/states-for-dashboard status=401 remote_addr=PRIVATE_INFORMATION time_ms=0 size=26 referer="PRIVATE_INFORMATION"
297:t=2019-05-20T11:48:01+0000 lvl=info msg="New state change" logger=alerting.resultHandler alertId=1 newState=ok prev state=unknown
298:t=2019-05-20T11:48:33+0000 lvl=info msg="Sending alert notification to" logger=alerting.notifier.email addresses=[PRIVATE@INFORMATION]
299:t=2019-05-20T11:48:33+0000 lvl=eror msg="Failed to send alert notification email" logger=alerting.notifier.email error="SMTP not configured, check your grafana.ini config file's [smtp] section."
300:t=2019-05-20T11:48:33+0000 lvl=eror msg="failed to send notification" logger=alerting.notifier uid= error="SMTP not configured, check your grafana.ini config file's [smtp] section."
[...]

我在我的服务器上找不到任何“grafana.ini”。

{ 编辑:我找到了两个。一个在“/var/lib/docker/overlay2/fe7[...]db3/diff/etc/grafana/grafana.ini”,另一个在“/var/lib/docker/overlay2/079[...]26d /merged/etc/grafana/grafana.ini”。两者都包含相同的信息,如“sample-ini”}

相反,我在正在运行的 grafana 容器中找到了一个“default.ini”和一个“sample.ini”文件。“default.ini”不包含任何与 SMTP 相关的内容,但“sample.ini”包含以下部分:

#################################### SMTP / Emailing ##########################
[smtp]
;enabled = false
;host = localhost:25
;user =
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
;password =
;cert_file =
;key_file =
;skip_verify = false
;from_address = admin@grafana.localhost
;from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com

[emails]
;welcome_email_on_sign_up = false

现在,我想,这是我应该配置 SMTP 的地方。有谁知道,如何告诉 docker-compose.yml / ansible,我想在容器设置期间配置此部分?
我已经在警报容器中定义了 SMTP 主机和其他信息。

4

2 回答 2

2

有两种方法:最常见的一种是将已经配置.ini的文件批量挂载到容器中,另一种是使用精细手册GF_SMTP_HOST=whatever中描述的形式的环境变量

于 2019-05-20T15:29:22.940 回答
0

我在我的 docker-compose 中使用了以下环境变量,它的工作就像魅力!

grafana:
image: grafana/grafana    
environment:
  - 'GF_SMTP_ENABLED=true'
  - 'GF_SMTP_HOST=smtp.gmail.com:587'
  - 'GF_SMTP_USER=user1@gmail.com'
  - 'GF_SMTP_PASSWORD=mysamplePassword'
  - 'GF_SMTP_FROM_ADDRESS=user1@gmail.com'
于 2021-01-21T16:35:14.903 回答