zabbix邮箱告警

1、安装postfix软件

[root@server ~]# yum -y install postfix
Last metadata expiration check: 18:30:18 ago on Sun 04 Sep 2022 04:11:22 PM CST.
Dependencies resolved.
===========================================================================================
 Package             Architecture       Version                     Repository        Size
===========================================================================================
Installing:
 postfix             x86_64             2:3.5.8-2.el8               base             1.5 M

Transaction Summary
===========================================================================================
Install  1 Package

Total download size: 1.5 M
Installed size: 4.3 M
Downloading Packages:
postfix-3.5.8-2.el8.x86_64.rpm                              71 kB/s | 1.5 MB     00:22
-------------------------------------------------------------------------------------------
Total                                                       71 kB/s | 1.5 MB     00:22
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                   1/1
  Running scriptlet: postfix-2:3.5.8-2.el8.x86_64                                      1/1
  Installing       : postfix-2:3.5.8-2.el8.x86_64                                      1/1
  Running scriptlet: postfix-2:3.5.8-2.el8.x86_64                                      1/1
  Verifying        : postfix-2:3.5.8-2.el8.x86_64                                      1/1

Installed:
  postfix-2:3.5.8-2.el8.x86_64

Complete!

2、修改postfix的主配置文件,并重启服务和设置下次启动生效

[root@server ~]#  vim /etc/postfix/main.cf
在该行后面加上$mydomain
mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
[root@server ~]# systemctl restart postfix.service
[root@server ~]#  systemctl enable postfix.service
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@server ~]#


3、安装mailx软件包

[root@server ~]# yum -y install mailx
Waiting for process with pid 4682 to finish.


Last metadata expiration check: 0:03:01 ago on Mon 05 Sep 2022 10:44:56 AM CST.
Dependencies resolved.
===========================================================================================
 Package            Architecture        Version                    Repository         Size
===========================================================================================
Installing:
 mailx              x86_64              12.5-29.el8                base              257 k

Transaction Summary
===========================================================================================
Install  1 Package

Total download size: 257 k
Installed size: 491 k
Downloading Packages:
mailx-12.5-29.el8.x86_64.rpm                               161 kB/s | 257 kB     00:01
-------------------------------------------------------------------------------------------
Total                                                      161 kB/s | 257 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                   1/1
  Installing       : mailx-12.5-29.el8.x86_64                                          1/1
  Running scriptlet: mailx-12.5-29.el8.x86_64                                          1/1
  Verifying        : mailx-12.5-29.el8.x86_64                                          1/1

Installed:
  mailx-12.5-29.el8.x86_64

Complete!

第三方邮箱警告配置

1、注册qq邮箱

2、开启SMTP服务和POP3服务,会生成一个授权码,需要记住这个授权码

3、修改报警媒介类型--email,密码是刚刚qq邮箱的授权码

进入163邮箱进行查看

配置动作

4、再次测试,agent1连接数超过7个时,看163邮箱是否能收到邮件

当连接数少于6个的时候,修复好了,163邮箱会再次收到修复成功的邮件

第三方邮箱+脚本告警配置

修改mailx配置文件

[root@server ~]# vim /etc/mail.rc

# Add mail-conf by Shu
set from=m13341394842@163.com
set smtp=smtp.163.com
set smtp-auth-user=m13341394842@163.com
set smtp-auth-password=GWVAZTXQPSOURCYB
set smtp-auth=login
set ssl-verify=ignore

[root@server ~]# chown -R zabbix.zabbix /etc/mail.rc
[root@server ~]#


编写脚本

[root@server ~]# vim /usr/lib/zabbix/alertscripts/mail-send.sh
[root@server ~]# cat /usr/lib/zabbix/alertscripts/mail-send.sh
#!/bin/bash
messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mailx -s "${subject}" $1
[root@server ~]# chmod +x /usr/lib/zabbix/alertscripts/mail-send.sh
[root@server ~]#  chown -R zabbix.zabbix /usr/lib/zabbix/alertscripts/mail-send.sh

测试

[root@server ~]# cd /usr/lib/zabbix/alertscripts/
[root@server alertscripts]# ./mail-send.sh  m13341394842@163.com "zhan" "test"

创建报警媒介

配置用户

配置动作


测试
将agent端连接数上升至8进行测试

[root@agent ~]# who | wc -l
8
[root@agent ~]#


posted @ 2022-09-05 20:21  舒少`  阅读(64)  评论(0)    收藏  举报