sendmail
systemctl status sendmail
postfix
systemctl status postfix.service
systemctl stop postfix.service
systemctl disable postfix.service
mailx
yum install mailx
dos2unix
yum install dos2unix -y
vim /etc/mail.rc
在最末尾增加
set from="xxx@163.com"
set smtp="smtp.163.com"
set smtp-auth-user="xxx@163.com"
set smtp-auth-password="password"
set smtp-auth="login"
echo "zabbix test"|mailx -s"zabbix alert" xxx@163.com
打开 zabbix_server.conf 查看 AlertScriptsPath
### Option: AlertScriptsPath
# Full path to location of custom alert scripts.
# Default depends on compilation options.
# To see the default path run command "zabbix_server --help".
#
# Mandatory: no
# Default:
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/lib/zabbix/alertscripts
进入该目录创建 mail.sh 文件
cd /usr/lib/zabbix/alertscripts
vim mail.sh
#! /bin/bash
SENT_TO=$1
SENT_SUBJECT=$2
SENT_CONTENT=$2
echo "$SENT_CONTENT" |mailx -v -s "$SENT_SUBJECT" $SENT_TO
chmod 777 mail.sh
./mail.sh 18827403358@163.com "zabbix test" "test"
去邮箱查看邮件
警告:
故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障!
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件 ID:{EVENT.ID}
恢复:
恢复{TRIGGER.STATUS}, 服务器:{HOSTNAME1}: {TRIGGER.NAME}已恢复!
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
故障持续时间: {EVENT.AGE}
恢复时间: {EVENT.RECOVERY.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件 ID:{EVENT.ID}
避免预警信息为附件的形式发送出来,所以修改一下配置文件为
#! /bin/bash
SENT_TO=$1
SENT_SUBJECT=$2
SENT_CONTENT="/tmp/alert_$$".tmp
echo "$3">$SENT_CONTENT
dos2unix $SENT_CONTENT
#echo "$SENT_CONTENT" |mailx -v -s "$SENT_SUBJECT" $SENT_TO
mailx -s "$SENT_SUBJECT" $SENT_TO<$SENT_CONTENT