修改mail配置
# vim /etc/mail.rc
## 在文件最后添加
set from=賬號(hào)
set smtp=smtps://smtp.exmail.qq.com:465
set ssl-verify=ignore
set nss-config-dir=/etc/zabbix/.certs
set smtp-auth-user=賬號(hào)
set smtp-auth-password=密碼
set smtp-auth=login
需要注意nss-config-dir的證書(shū)配置,zabbix需要具有對(duì)應(yīng)權(quán)限
使用加密端口:465
創(chuàng)建證書(shū)認(rèn)證
創(chuàng)建加密證書(shū)
mkdir /root/.certs
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d .certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/ -i ~/.certs/qq.crt
需要修改對(duì)應(yīng)的郵箱服務(wù)器地址和證書(shū)的相關(guān)路徑
測(cè)試發(fā)送
mail -v -s "subject_title" 測(cè)試郵箱地址 < /etc/passwd
郵件腳本
#!/bin/bash
#send mail
echo "$3" | mail -s "$2" $1 >>/tmp/mailx.log 2>&1 #$1:收件人郵箱地址;$2:郵件標(biāo)題;$3:郵件內(nèi)容
需要對(duì)腳本進(jìn)行授權(quán),對(duì)輸出日志文件進(jìn)行授權(quán)
注意事項(xiàng)
zabbix上配置好郵件告警后,需要給對(duì)應(yīng)的用戶(hù)所屬主機(jī)組進(jìn)行授權(quán),否則不能發(fā)送告警郵件
郵件腳本的目錄需要修改,編輯zabbix_server.conf 修改AlertScriptsPath=/etc/zabbix/script