yum install mailx -y vi /etc/mail.rc set from=[email protected] set smtp=smtp.exmail.qq.com set smtp-auth-user=[email protected] set smtp-auth-password=Jxxxx set smtp-auth=login
测试
echo "hello world" | mail -s "testmail" [email protected]
编辑发邮件脚本
cd /usr/lib/zabbix/alertscripts vi mailx.sh #!/bin/bash #send mail messages=`echo $3 | tr '\r\n' '\n'` subject=`echo $2 | tr '\r\n' '\n'` echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1
修改权限
touch /tmp/mailx.log chown -R zabbix.zabbix /tmp/mailx.log chmod +x /usr/lib/zabbix/alertscripts/mailx.sh chown -R zabbix.zabbix /usr/lib/zabbix/
测试
./mailx.sh xxxxx@139.com "主题" "内容"
zabbix前台配置
管理 --> 报警媒介类型 --> 创建媒体类型
管理 --> 用户 --> admin -->报警媒介 --> 更新
![](https://img2018.cnblogs.com/blog/1183304/201904/1183304-20190411175459411-644522603.png)
配置 --> 动作 --> (触发器)创建动作
![](https://img2018.cnblogs.com/blog/1183304/201904/1183304-20190411175811979-382159011.png)
![](https://img2018.cnblogs.com/blog/1183304/201904/1183304-20190411175821144-1008847631.png)
![](https://img2018.cnblogs.com/blog/1183304/201904/1183304-20190411175827974-863582305.png)
告警主机: {HOSTNAME1}
告警时间: {EVENT.DATE} {EVENT.TIME}
告警等级: {TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目: {TRIGGER.KEY1}
问题详情: {ITEM.NAME}: {ITEM.VALUE}
当前状态: {TRIGGER.STATUS}: {ITEM.VALUE1}
事件ID: {EVENT.ID}
恢复主机:{HOSTNAME1}
恢复时间:{EVENT.DATE} {EVENT.TIME}
恢复等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
测试zabbix agent断链