根據網絡教程實現。zabbix3.4,使用腳本和sendemail。
1.下載并解壓縮sendemail到/usr/local/bin下面,修改權限。
下載網址:
sendemail - send email with this free command line email client http://caspian.dotconf.net/menu/software/sendemail/
修改權限:
chown zabbix:zabbix /usr/local/bin/sendemail
2.進行發郵件測試。
1
|
/usr/local/bin/sendemail -f xxxx@163.com(發件郵箱) -s smtp.163.com -u "郵件標題" -m "郵件內容" -o message-content-type=html -o message-charset=utf8 -xu xxxx@163.com(發件郵箱賬號) -xp “網易郵箱授權碼” -t “目標郵箱” |
3.發郵件測試通過后,進入/usr/local/zabbix/share/zabbix/alertscripts/目錄,并新建mail.sh文件,授予權限;
4.mail.sh內容:
1
2
3
4
5
|
#!/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 "郵箱客戶端授權碼" -m "$body" |
5.測試報錯
1
2
3
4
5
6
7
8
9
10
11
|
[root@centos7 alertscripts]# ./mail.sh “目標郵箱” 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行的內容,從
if (! io::socket::ssl->start_ssl($server, ssl_version => ‘sslv3 tlsv1‘)) {
修改為
if (! io::socket::ssl->start_ssl($server)) {
再次測試,成功。
1
2
3
4
5
6
7
8
9
10
11
|
[root@centos7 alertscripts] # ./mail.sh “目標郵箱” 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負責判斷,發送郵件;media type負責選擇腳本,傳遞參數;users負責明確告警信息發送給誰等信息。
按照官網的介紹配置即可,這部分實在懶得寫了。唯一需要注意的是,media type需要添加3個參數,分別是{alert.sendto},{alert.subject},{alert.mesage},分別對于mail.sh中的to、subject和body。
7.最后,點擊“reports”-“action log”,可以查看郵件是否發送成功,不成功的原因。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對服務器之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
原文鏈接:https://blog.csdn.net/zsx0728/article/details/81510017