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自定义的指定目录
/usr/lib/zabbix/alertscripts/
默认是开启的
grep -n ^[a-Z] /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
91:DBName=zabbix
107:DBUser=zabbix
115:DBPassword=xxxxx
287:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
413:Timeout=4
455:AlertScriptsPath=/usr/lib/zabbix/alertscripts
465:ExternalScripts=/usr/lib/zabbix/externalscripts
501:LogSlowQueries=3000
4、编辑发邮件脚本
cd /usr/lib/zabbix/alertscripts/
vim sendEmail.sh
#!/bin/bash
to=$1
subject=$2
body=$3
from=test@qq.com
smtp=smtp.qq.com
passwd=testpasswd
/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"
chmod +x sendEmail.sh
chown zabbix.zabbix sendEmail.sh