1、邮件发送配置
[root@Zabbix ~]# yum -y install mail #如有mail命令则不用安装
[root@Zabbix ~]# vim /etc/mail.rc
# Display the recipients of messages sent by the user himself in
# header summaries.
set showto
# Automatically check for new messages at each prompt, but avoid polling
# of IMAP servers or maildir folders.
set newmail=nopoll
# If threaded mode is activated, automatically collapse thread.
set autocollapse
# Hide some header fields which are uninteresting for most human readers.
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding
# Only include selected header fields when forwarding messages.
fwdretain subject date from to
# For Linux and BSD, this should be set.
set from=richardcnhm@sina.com #发送的邮件地址
set smtp=smtp.sina.com #外部smtp服务器的地址
set smtp-auth-user=richardcnhm@sina.com #外部smtp服务器认证的用户名
set smtp-auth-password=123456 #外部smtp服务器认证的用户密码(如用163或qq邮箱则为授权码)
set smtp-auth=login #邮件认证的方式
[root@Zabbix ~]# echo "邮件正文"|mail -s "邮件主题" 收件人地址 #发送邮件测试命令
2、告警脚本内容
[root@Zabbix ~]# yum -y install dos2unix
[root@Zabbix ~]# vim /usr/lib/zabbix/alertscripts/mail.sh
#!/bin/bash
# use mailx to send mail
# 20141127 carl 1st
# PATH
file=/tmp/zabbix_mail.txt
echo "$3" > $file
dos2unix -k $file
/bin/mail -s "$2" $1 < $file
# echo "$3" | mail -s "$2" $1
#注:使用dos2unix工具是为解决zabbix发送邮件出现乱码和收到的邮件是*.bin的情况
#$3 是前端定义的邮件内容,$2是前端定义的主题,$1是前端定义的收件人
[root@Zabbix alertscripts]# chmod 777 mail.sh
[root@Zabbix alertscripts]# chown zabbix.zabbix mail.sh
3、配置使用脚本报警
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
4、默认信息(发送邮件正文)
告警主机: {HOSTNAME1}
告警项目:{TRIGGER.KEY1}
当前状态: {TRIGGER.STATUS}
告警信息: {TRIGGER.NAME}
告警等级: {TRIGGER.SEVERITY}
告警时间: {EVENT.DATE} {EVENT.TIME}
问题详情: {ITEM.NAME1}({ITEM.VALUE1})
事件 ID: {EVENT.ID}
5、微信报警使用wechat脚本
测试命令
# ./wechat –corpid="你的企业应用ID" –corpsecret="你的创建的企业应用的Secret" –msg="您好,告警测试" –user="微信消息接收者的企业微信账号" –agentid=你的创建的企业应用的agentid
返回{'errcode': 0, 'errmsg': 'ok', 'invaliduser': ''},即为消息发送成功
参考链接:
https://blog.csdn.net/GX_1_11_real/article/details/80366621 #zabbix微信告警设置