zabbix郵件報警
一、安裝軟件使用腳本發送
-
安裝軟件包
yum -y install mailx #選做:給/bin目錄下設置權限 Chown -R zabbix.zabbix /bin/mail
-
編輯/etc/mail.rc
1).smtps方式發送郵件
set from=397011884@qq.com #阿里雲默認禁用25端口,不給開放所以使用465端口發送 set smtp=smtps://smtp.qq.com:465 set smtp-auth-user=397011884@qq.com set smtp-auth-password=rikvwnuqdfnpbgce set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/etc/pki/nssdb #參數說明 from是發送的郵件地址 smtp是發生的外部smtp服務器的地址 smtp-auth-user是外部smtp服務器認證的用戶名。注意一定要填寫郵件全稱!! smtp-auth-password是外部smtp服務器認證的用戶密碼 smtp-auth是郵件認證的方式
#提示 “Error in certificate: Peer’s certificate issuer is not recognized #解決方法: mkdir -p /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 SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt certutil -L -d /root/.certs #生成完成之后,修改 mail.rc 郵件配置,修改 nss-config-dir 為上面命令生成的 /root/.certs,保存 certutil -L -d /root/.certs #列出目錄下證書 Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI GeoTrust SSL CA
# Error in certificate: Peer's certificate issuer is not recognized. cd /root/.certs/ ll certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
-
測試
echo "zabbix" | mail -s 'zabbix' 397011884@qq.com
二、直接填寫使用
郵箱設置的原理是Zabbix服務中集成了郵箱客戶端功能,登錄一個網絡郵箱賬號(因此必須事先注冊一個網絡郵箱地址),然后以此郵箱地址為發件地址向需要接收報警的郵箱發送報警郵件
創建完報警媒介先測試一下:
來到主界面,點擊測試,並發送郵件看是否成功,建議使用同域名郵箱
配置賬號訪問時發送郵件
如果要監控所有賬號登陸,配置/etc/bashrc;監控指定賬號,在該賬號默認目錄下,編輯.bashrc,我要監控的是root,加入如下內容
echo "ALERT - Root Shell Access (`hostname`) on:" `date` `who` | mail -s "`hostname` Root Access from `who | cut -d'(' -f2 | cut -d')' -f1`" samgg@domainname.com
即時生效:source .bashrc
再次使用root登錄時,samgg@domainname.com即可收到來自server@domainname.com的郵件。
ERROR錯誤:
#頁面提示:Login denied: Authentication failed: 550
#日志提示:failed to send email: Login denied: Authentication failed: 550
#原因:
郵箱服務器沒有開啟第三方授權碼
#解決:
啟用授權碼
#頁面提示: Login denied: Authentication failed: 535
#日志提示:failed to send email: Login denied: Authentication failed: 535
#原因:
密碼錯誤:(注意密碼不是郵箱登錄密碼,是郵箱系統設置的第三方程序登錄的授權碼)
用戶名稱錯誤:(應填寫@符號以前部分,或者完整郵箱地址)
SMTP服務器端口錯誤:(注意安全鏈接類型,如果選無端口為25;選SSL/TLS 得根據具體郵箱使用協議而定,如果是SSL端口為465,如果是TLS端口是587)
SMTP服務器錯誤:(填寫正確的服務器地址,必須選擇發件服務器地址,例如163郵箱為:smtp.163.com qq郵箱為:smtp.qq.com)
SMTP HELO 錯誤:(填寫郵箱域名例如163.com qq.com 或者填寫SMTP服務器地址)
#解決:
應該輸入授權碼,正確的用戶名稱和正確的端口號。
注意配置完成后重啟zabbix-Server 服務。
#頁面提示:連接超時 3 秒超出當連接Zabbix 服務器 "localhost".
#原因:
服務器配置沒有生效。
#解決:
#重啟zabbix-Server 服務。(Centos7:# systemctl restart zabbix-server)
#頁面提示:Support for SMTP authentication was not compiled in
#日志提示:failed to send email: Support for SMTP authentication was not compiled in
#原因:
SMTP協議沒有zabbix server 中編譯,打開日志文件,在zabbix-server剛啟動后可以看到下面日志,
12801:20190513:141300.293 Starting Zabbix Server. Zabbix 4.2.1 (revision 92832).
12801:20190513:141300.293 ****** Enabled features ******
12801:20190513:141300.293 SNMP monitoring: YES
12801:20190513:141300.293 IPMI monitoring: YES
12801:20190513:141300.293 Web monitoring: YES
12801:20190513:141300.293 VMware monitoring: YES
12801:20190513:141300.293 SMTP authentication: NO
12801:20190513:141300.293 Jabber notifications: NO
12801:20190513:141300.293 Ez Texting notifications: YES
12801:20190513:141300.293 ODBC: YES
12801:20190513:141300.293 SSH2 support: YES
12801:20190513:141300.293 IPv6 support: YES
12801:20190513:141300.293 TLS support: YES
#主要原因是主機的系統是Centos 6 ,Centos 6支持的最新版本的curl 版本是7.19.7(# curl -V 可以查看下), Zabbix server 如果要支持 SMTP authentication ,需要 libcurl version 7.20 或以上版本,因此需要安裝 7.20以上的libcurl,
#解決:
更新cuel ,然后下載rpm,重新安裝Zabbix-server。