配置smtp
如果要通过grafana接收告警邮件,都需要配置邮箱。而相关配置文件就是grafana.ini
,分别要修改如下几个地方:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#################################### SMTP / Emailing ##########################
[smtp]
enabled = true
host = smtp.163.com:465
user = 邮箱前缀@163.com
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = 客户端授权密码
;cert_file =
;key_file =
skip_verify = true
from_address = 邮箱前缀@163.com
from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com
#################################### Alerting ############################
[alerting]
# Disable alerting engine & UI features
;enabled = true
# Makes it possible to turn off alert rule execution but alerting UI is visible
execute_alerts = true
我采用了网易邮箱,把文件保存退出之后,重启一下grafana-server
。然后在页面的alatm页面里配置Notification channels
,如图:
如果发送不成功,去查看一下日志,日志地址是/var/log/grafana/grafana.log
。如果发送成功了,那么邮箱会收到这样的一个邮件:
邮箱密码问题问题
这里要注意几个问题!
- 阿里云的服务器出于安全考虑默认是不会开放25端口的,如果你非要用阿里云的服务器去打开25端口,请移步https://www.alibabacloud.com/help/zh/doc-detail/56130.htm ;
- 如果不想麻烦阿里云那么就要使用其他端口,比如我配置文件里面写的加密的465端口,这个端口不能使用登陆邮箱的普通密码,而是需要填写“授权码”;
- 以网易邮箱为例,首先先要打开
POP3/SMTP服务
,如图:
其次然后在客户端授权密码
里设置一个新的密码,如图:
然后把这个授权码填写到grafana.ini
里,填邮箱的登录密码是错误的。
参考资料
http://www.kubiops.com/blog/2017/02/27/Grafana%E5%91%8A%E8%AD%A6%E9%85%8D%E7%BD%AE.html