zabbix3邮件告警
本人使用的zabbix版本为3.2.4,zabbix 3版本应该通用
1、sendEmail安装:
cd /usr/local/src/
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
yum install perl-Net-SSLeay perl-IO-Socket-SSL -y
tar -xvf sendEmail-v1.56.tar.gz
cd sendEmail-v1.56/
cp -ra sendEmail /usr/local/bin/
chmod +x /usr/local/bin/sendEmail
ls -d /usr/local/bin/sendEmail
2、测试sendEmail
参数说明:
/usr/local/bin/sendEmail 命令主程序
-f from@163.com 发件人邮箱
-t to@163.com 收件人邮箱
-s smtp.163.com 发件人邮箱的smtp服务器
-u "我是邮件主题" 邮件的标题
-o message-content-type=html 邮件内容的格式,html表示它是html格式
-o message-charset=utf8 邮件内容编码
-xu from@163.com 发件人邮箱的用户名
-xp 123456 发件人邮箱密码
-m "我是邮件内容" 邮件的具体内容
/usr/local/bin/sendEmail -f test@qq.com -t test@qq.com -s test@qq.com -u "zabbxitest" -o message-content-type=html -o message-charset=utf8 -xu test@qq.com -xp 123456 -m "我是测试"
3,zabbix自定义的指定目录
vim /usr/local/zabbix/etc/zabbix_server.conf
AlertScriptsPath=/data/zabbix/alertscripts
重启zabbix_server
4.在定义路径下创建发送邮件脚本
此处邮箱密码为163邮箱smtp授权码,需要去邮箱将smtp功能打开
vim /data/zabbix/alertscripts/send.sh
#!/bin/bash
# 知道发送目标邮箱
to=$1
#邮件标题
subject=$2
#邮件内容
body=$3
from=xxxxxx@163.com
smtp=smtp.163.com
passwd=geenk
/usr/local/bin/sendEmail -f "$from" -t "$to" -s "$smtp" -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu "$from" -xp "$passwd" -m "$body"
测试脚本能否发送邮件:
chown -R zabbix:zabbix /data/zabbix/alertscripts/send.sh
./send.sh xxx@163.com 11 11
注意:centos7下运行发送有可能报错:
[root@localhost alertscripts]# ./send.sh xx@163.com 11 11
*******************************************************************
Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
together 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 424.
原因:
[root@localhost alertscripts]# perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 34 registered patches, see perl -V for more detail)
Copyright 1987-2012, Larry Wall
由于在CentOS 7下perl的版本为5.16,而centos6.5的是5.10,版本不兼容
解决:
/usr/local/bin/sendEmail -f "$from" -t "$to" -s "$smtp" -u "$subject" -o message-content-type=html -o message-charset=utf8-xu "$from" -xp "$passwd" -m "$body" -o tls=no
加上tls=no参数就可以了
[root@localhost alertscripts]# ./send.sh xx@163.com 11 11
Nov 16 13:57:52 localhost sendEmail[34132]: Email was sent successfully!
5 zabbix web段配置:
1、填写报警媒介类型
此处脚本名字不能写错
参数:
{ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE}
2、填写报警媒介用户
3、填写动作
参数:
默认接收人:{TRIGGER.STATUS}:{TRIGGER.NAME}
默认信息
告警主机: {HOSTNAME1}<br/>
告警时间: {EVENT.DATE}{EVENT.TIME}<br/>
告警等级: {TRIGGER.SEVERITY}<br/>
告警信息: {TRIGGER.NAME}<br/>
告警项目: {TRIGGER.KEY1}<br/>
问题详情: {ITEM.NAME}: {ITEM.VALUE}<br/>
当前状态: {TRIGGER.STATUS}: {ITEM.VALUE1}<br/>
事件ID: {EVENT.ID}<br/>
细节:
恢复操作:
完成后可以测试了,
停止客户端agent服务,大约等五分钟左右收到告警邮件