报错信息
level=error ts=2022-02-10T06:51:18.830455313Z caller=impl.go:307 msg="failed to close SMTP connection" err="tls: use of closed connection"
level=error ts=2022-02-10T06:51:20.741666382Z caller=impl.go:307 msg="failed to close SMTP connection" err="tls: use of closed connection"
level=error ts=2022-02-10T06:51:24.320520947Z caller=impl.go:307 msg="failed to close SMTP connection" err="tls: use of closed connection"
level=error ts=2022-02-10T06:51:26.514535816Z caller=notify.go:332 component=dispatcher msg="Error on notify" err="*notify.loginAuth failed: 535 Login Fail. Please enter your authorization code to login. More information in http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256"
问题解决
这个问题在网上搜索了,发现是邮箱授权码的问题,但是我的授权码是正确的(我使用的是QQ邮箱)
接下来我尝试重新申请一个授权码进行测试,发现还是报一样的错误,所有不是授权码的问题,应该是模板文件配置错误的问题
接下来我将模板文件修改为全英文,还是报一样的错误
猜测应该是目标文件里面的内容错误,但是测试文件发现是正确的啊
[root@localhost alertmanager]# ./amtool check-config alertmanager1.yml
Checking 'alertmanager1.yml' SUCCESS
Found:
- global config
- route
- 1 inhibit rules
- 1 receivers
- 1 templates
SUCCESS
[root@localhost alertmanager]#
接下来我将模板文件里面的邮箱地址修改为具体的地址便可以进行报警了
原来的配置信息:
[root@localhost alertmanager]# vim alertmanager1.yml
global:
resolve_timeout: 5m
smtp_from: '{{ template "email.from" . }}'
smtp_smarthost: 'smtp.qq.com:465'
smtp_auth_username: '{{ template "email.from" . }}'
smtp_auth_password: 'dbvlpkuyociiggeh'
smtp_require_tls: false
smtp_hello: 'qq.com'
templates:
- '/opt/prometheus/alertmanager/template/email.tmpl'
route:
group_by: ['alertname']
group_wait: 1s
group_interval: 1s
repeat_interval: 1m
receiver: 'email'
receivers:
- name: 'email'
email_configs:
- to: '{{ template "email.to" . }}'
html: '{{ template "email.to.html" . }}'
send_resolved: true
inhibit_rules:
"alertmanager1.yml" 29L, 734C 已写入
测试配置是否正确
[root@localhost alertmanager]# ./amtool check-config alertmanager1.yml
Checking 'alertmanager1.yml' SUCCESS
Found:
- global config
- route
- 1 inhibit rules
- 1 receivers
- 1 templates
SUCCESS
查看模板信息
[root@localhost alertmanager]# cat template/email.tmpl
{{ define "email.from" }}154***775@qq.com{{ end }}
{{ define "email.to" }}154***775@qq.com{{ end }}
{{ define "email.to.html" }}
{{ range .Alerts }}
=========start==========<br>
告警程序: prometheus_alert <br>
告警级别: {{ .Labels.severity }} 级 <br>
告警类型: {{ .Labels.alertname }} <br>
故障主机: {{ .Labels.instance }} <br>
告警主题: {{ .Annotations.summary }} <br>
告警详情: {{ .Annotations.description }} <br>
触发时间: {{ .StartsAt.Format "2019-08-04 16:58:15" }} <br>
=========end==========<br>
{{ end }}
{{ end }}
修改后的模板信息
[root@localhost alertmanager]# vim alertmanager1.yml
smtp_require_tls: false
global:
resolve_timeout: 5m
smtp_from: '154***775@qq.com'
smtp_smarthost: 'smtp.qq.com:465'
smtp_auth_username: '154***775@qq.com'
smtp_auth_password: 'dbv**pk***iggeh'
smtp_require_tls: false
templates:
- '/opt/prometheus/alertmanager/template/email.tmpl'
route:
group_by: ['alertname']
group_wait: 1s
group_interval: 1s
repeat_interval: 1m
receiver: 'email'
receivers:
- name: 'email'
email_configs:
- to: '1542762775@qq.com'
html: '{{ template "email.to.html" . }}'
send_resolved: true
inhibit_rules:
- source_match:
"alertmanager1.yml" 28L, 677C 已写入
[root@localhost alertmanager]#
最终出现的效果为:
恢复node节点后: