邮箱告警报错: msg=“Error on notify“ err=“*notify.loginAuth failed: 535 Login Fail

博客讲述了在使用Prometheus Alertmanager过程中遇到的SMTP邮件发送失败问题,错误信息提示授权码错误。经过排查,确认授权码无误,并尝试修改模板文件为全英文和使用具体邮箱地址,最后发现是模板文件中邮箱地址配置为变量导致的问题。通过将模板文件的邮箱地址改为实际地址后,邮件报警成功发送。
摘要由CSDN通过智能技术生成

报错信息

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节点后:

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

?abc!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值