zabbix实现邮件告警的方法

根据网络教程实现。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.进行发邮件测试。

/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内容:

#!/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.测试报错

[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)) {

再次测试,成功。

[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”,可以查看邮件是否发送成功,不成功的原因。

赞(0)
声明:本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-62778877-8306;邮箱:fanjiao@west.cn。本站原创内容未经允许不得转载,或转载时需注明出处:西部数码知识库 » zabbix实现邮件告警的方法

登录

找回密码

注册