安裝mailx
[[email protected] ~]# yum -y install mailx
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: us-east.repo.webtatic.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
nginx | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
webtatic | 3.6 kB 00:00:00
軟體包 mailx-12.5-19.el7.x86_64 已安裝并且是最新版本
無須任何處理
配置郵箱
[[email protected] ~]# vim /etc/mail.rc
set [email protected]
set smtp=smtp.qq.com
set [email protected]
set smtp-auth-password=xfcffumyrfpsbgcc
set smtp-auth=login
測試發送郵件
如果出現如下報錯,是因為smtp-auth-password要填寫授權碼而非郵箱登陸密碼
如何獲得郵箱授權碼?
發送短信之後點選“我已發送”就會出現如下界面,把授權碼複制到smtp-auth-password即可
編寫自動化腳本
[[email protected] ~]# cd /usr/lib/zabbix/alertscripts
[[email protected] alertscripts]# vim 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
建立日志檔案
修改屬主屬組
[[email protected] alertscripts]# chown -R zabbix.zabbix /tmp/mailx.log
[[email protected] alertscripts]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh
[[email protected] alertscripts]# chown -R zabbix.zabbix /usr/lib/zabbix/
測試自動化腳本
建立報警媒介類型
配置以什麼方式發送告警郵件
配置使用者
配置發送到管理者的郵箱
配置報警動作
配置當出現異常時報警郵件發送的頻率和内容,以及異常恢複以後發送的郵件内容