邮件告警
//关闭postfix服务并设置开机不自启
[root@wbk ~]# systemctl stop postfix
[root@wbk ~]# systemctl disable postfix.service
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
[root@wbk ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:139 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 50 *:445 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 50 :::139 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 50 :::445 :::*
LISTEN 0 80 :::3306 :::*
//安装邮件发送工具mailx
[root@wbk ~]# yum -y install mailx
已安装:
mailx.x86_64 0:12.5-19.el7
完毕!
//修改配置文件
[root@wbk ~]# vim /etc/mail.rc
set from=936875530@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=936875530@qq.com
set smtp-auth-password=sdatqtuunosubbdf
set smtp-auth=login
//通过mail命令手动测试发送邮件
[root@wbk ~]# echo 'zabbix mail send test' | mail -s 'zabbix' 936875530@qq.com
//查看邮件
//添加告警媒介
需要添加的内容
//制定一个用户使用脚本发送邮件
//创建告警动作
//创建动作完成
//修改配置文件
[root@wbk ~]# cd /usr/local/etc/
[root@wbk etc]# mkdir alertscripts
[root@wbk ~]# vim /usr/local/etc/zabbix_server.conf
#AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/local/etc/alertscripts
//进入创建的目录写脚本
[root@wbk ~]# cd /usr/local/etc/alertscripts/
[root@wbk alertscripts]# ls
[root@wbk alertscripts]# cat mail.sh
#!/bin/bash
message=$3
subject=$2
echo "$message" | mail -s "$subject" $1
//给这个脚本执行权限,给alertscripts目录zabbix用户
[root@wbk alertscripts]# chmod +x mail.sh
[root@wbk etc]# chown -R zabbix.zabbix alertscripts/
[root@wbk etc]# ll alertscripts/
总用量 32
drwxr-xr-x. 2 zabbix zabbix 21 2月 26 15:33 alertscripts
//重启zabbix服务
[root@wbk ~]# pkill zabbix
[root@wbk ~]# zabbix_server
[root@wbk ~]# zabbix_agentd
//往以前创建的触发告警的文件里输入文件
[root@wbk ~]# echo 'zabbix mail send' | mail -s 'zabbix' 936875530@qq.com
这里是传不过去的,因为有东西忘了写,这里少了三个参数,添加进去就可以了
查看邮箱,发现多出了两个邮件
//下载发送到邮箱的文件到Xshell能看到内容
[root@wbk ~]# cat tcmime.900.900.1136.bin
Problem started at 16:33:36 on 2019.02.26
Problem name: /opt/cc 文件发生了改变
Host: web服务器-192.168.189.132
Severity: Warning
Original problem ID: 98