zabbix续(邮件告警)

邮件告警
//关闭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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值