zabbix邮件报警 465

#启动邮箱服务
systemctl start postfix.service
#配置用户的邮箱发送邮件
vim /etc/mail.rc
set from="[email protected]"
set smtp=" smtps://smtp.exmail.qq.com:465"
set smtp-auth-user="[email protected]"
set smtp-auth-password="xxxxxx"
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb
#测试发送邮件
[root@VM_centos ~]# echo "messages" | mail -v -s "subject" [email protected]
Resolving host smtp.exmail.qq.com . . . done.
Connecting to 163.177.90.125:465 . . . connected.
Error in certificate: Peer's certificate issuer is not recognized.
Comparing DNS name: "pop.qq.com"
Comparing DNS name: "ex.qq.com"
Comparing DNS name: "imap.exmail.qq.com"
Comparing DNS name: "rtx.exmail.qq.com"
Comparing DNS name: "smtp.exmail.qq.com"
SSL parameters: cipher=AES-128, keysize=128, secretkeysize=128,
issuer=CN=GeoTrust RSA CA 2018,OU=www.digicert.com,O=DigiCert Inc,C=US
subject=CN=pop.qq.com,OU=R&D,O=Shenzhen Tencent Computer Systems Company Limited,L=Shenzhen,ST=Gu
220 smtp.qq.com Esmtp QQ Mail Server
...
>>> QUIT
221 Bye
#解决证书解析报错
#手动的获取QQ 邮箱的证书保存到本地指定的目录里以备调用和验证
[root@VM_centos ~]# cd /etc/pki/nssdb/
[root@VM_centos nssdb]# ls
cert8.db cert9.db key3.db key4.db pkcs11.txt secmod.db
[root@VM_centos nssdb]# echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' >qq.crt
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = GeoTrust RSA CA 2018
verify return:1
depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Shenzhen Tencent Computer Systems Company Limited, OU = R&D, CN = pop.qq.com
verify return:1
DONE
[root@VM_centos nssdb]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /etc/pki/nssdb -i qq.crt
[root@VM_centos nssdb]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /etc/pki/nssdb -i qq.crt
[root@VM_centos nssdb]# certutil -L -d /etc/pki/nssdb
#进入邮箱 SSL 证书存放目录,为了信任证书的标记操作
[root@VM_centos nssdb]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
Notice: Trust flag u is set automatically if the private key is present.
#解决发送是附件
#只要把行尾^M去掉,然后发送的话就不会是附件的形式了
[root@VM_centos nssdb]# yum -y install dos2unix.x86_64
[root@VM_centos nssdb]# vim /usr/lib/zabbix/alertscripts/sendmail.sh
#!/bin/bash
TMP_FILE=/usr/lib/zabbix/alertscripts/tmp_messages.txt
 
echo $3 > ${TMP_FILE}
dos2unix ${TMP_FILE} #解决发送的邮件内容变成附件的问题
subject=$2
mail -s "${subject}" $1 >>/var/log/sendmail.log 2>&1 <${TMP_FILE}
 
#注意权限是chown zabbix.zabbix
#zabbix 管理---->报警媒介类型
#查看zabbix脚本位置
[root@VM_centos alertscripts]# grep alertscripts /etc/zabbix/zabbix_server.conf
AlertScriptsPath=/usr/lib/zabbix/alertscripts
 

猜你喜欢

转载自www.cnblogs.com/DemonAngel/p/9223789.html
今日推荐