zabbix實現(xiàn)郵件告警的方法
根據(jù)網(wǎng)絡(luò)教程實現(xiàn)。zabbix3.4,使用腳本和sendEmail。
1.下載并解壓縮sendEmail到/usr/local/bin下面,修改權(quán)限。
下載網(wǎng)址:
SendEmail - Send email with this free command line email client http://caspian.dotconf.net/menu/Software/SendEmail/
修改權(quán)限:
chownzabbix:zabbix/usr/local/bin/sendEmail
2.進(jìn)行發(fā)郵件測試。
/usr/local/bin/sendEmail -f xxxx@163.com(發(fā)件郵箱) -s smtp.163.com -u "郵件標(biāo)題" -m "郵件內(nèi)容" -o message-content-type=html -o message-charset=utf8 -xu xxxx@163.com(發(fā)件郵箱賬號) -xp “網(wǎng)易郵箱授權(quán)碼” -t “目標(biāo)郵箱”
3.發(fā)郵件測試通過后,進(jìn)入/usr/local/zabbix/share/zabbix/alertscripts/目錄,并新建mail.sh文件,授予權(quán)限;
4.mail.sh內(nèi)容:
#!/bin/bash to=$1 subject=$2 body=$3 /usr/local/bin/sendEmail -o tls=auto -f xxxx@163.com -t "$to" -s smtp.163.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu xxxx@163.com -xp "郵箱客戶端授權(quán)碼" -m "$body"
5.測試報錯
[root@centos7 alertscripts]# ./mail.sh “目標(biāo)郵箱” test_topic hello_world! ******************************************************************* Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER possibly with SSL_ca_file|SSL_ca_path for verification. If you really don't want to verify the certificate and keep the connection open to Man-In-The-Middle attacks please set SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application. ******************************************************************* at /usr/local/bin/sendEmail line 1906. invalid SSL_version specified at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 444.
在sendemail中1906行的內(nèi)容,從
if (! IO::Socket::SSL->start_SSL($SERVER, SSL_version => ‘SSLv3 TLSv1‘)) {
修改為
if (! IO::Socket::SSL->start_SSL($SERVER)) {
再次測試,成功。
[root@centos7 alertscripts]# ./mail.sh “目標(biāo)郵箱” test_topic hello_world! ******************************************************************* Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER possibly with SSL_ca_file|SSL_ca_path for verification. If you really don't want to verify the certificate and keep the connection open to Man-In-The-Middle attacks please set SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application. ******************************************************************* at /usr/local/bin/sendEmail line 1906. Aug 08 15:42:42 wanbu sendEmail[25763]: Email was sent successfully!
6.zabbix-web配置
在zabbix3.4中,有3處需要配置,actions,media type,users。actions負(fù)責(zé)判斷,發(fā)送郵件;media type負(fù)責(zé)選擇腳本,傳遞參數(shù);users負(fù)責(zé)明確告警信息發(fā)送給誰等信息。
按照官網(wǎng)的介紹配置即可,這部分實在懶得寫了。唯一需要注意的是,media type需要添加3個參數(shù),分別是{ALERT.SENDTO},{ALERT.SUBJECT},{ALERT.MESAGE},分別對于mail.sh中的to、subject和body。

7.最后,點擊“Reports”-“action log”,可以查看郵件是否發(fā)送成功,不成功的原因。

總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對本站的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信