Zabbix三种邮箱告警配置

环境

环境 IP地址 主机名 需要安装的应用 系统版本
服务端 192.168.23.140 zabbix lamp zabbix_server zabbix_agent CentOS 8
客户端 192.168.23.141 node1 zabbix_agent CentOS 8

本地邮箱告警配置

//安装mailx和postfix
[root@zabbix ~]# yum -y install mailx postfix

//启动postfix并设置开机自启
[root@zabbix ~]# systemctl enable --now postfix
[root@zabbix ~]# ss -antl
State          Recv-Q         Send-Q                 Local Address:Port                  Peer Address:Port        
LISTEN         0              128                          0.0.0.0:22                         0.0.0.0:*           
LISTEN         0              100                        127.0.0.1:25                         0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:10050                      0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:10051                      0.0.0.0:*           
LISTEN         0              128                        127.0.0.1:9000                       0.0.0.0:*           
LISTEN         0              128                                *:80                               *:*           
LISTEN         0              128                             [::]:22                            [::]:*           
LISTEN         0              100                            [::1]:25                            [::]:*           
LISTEN         0              80                                 *:3306                             *:*           
//修改域名
[root@zabbix ~]# hostnamectl set-hostname zabbix.example.com
[root@zabbix ~]# bash
[root@zabbix ~]# hostname
zabbix.example.com

//给邮箱发送邮件
[root@zabbix ~]# echo 'test' | mail -s "123456" yanchuanglol@163.com

本地邮箱+脚本告警配置

本地邮箱告警脚本目录默认是/usr/local/share/zabbix/alertscripts

[root@zabbix ~]# vim /usr/local/etc/zabbix_server.conf
......
### Option: AlertScriptsPath
#       Full path to location of custom alert scripts.
#       Default depends on compilation options.
#       To see the default path run command "zabbix_server --help".
#
# Mandatory: no
# Default:
AlertScriptsPath=/usr/local/share/zabbix/alertscripts     //取消注释并修改成绝对路径
......
[root@zabbix ~]# pkill zabbix
[root@zabbix ~]# zabbix_server
[root@zabbix ~]# zabbix_agentd
[root@zabbix ~]# ss -antl
State          Recv-Q         Send-Q                 Local Address:Port                  Peer Address:Port        
LISTEN         0              128                          0.0.0.0:22                         0.0.0.0:*           
LISTEN         0              100                        127.0.0.1:25                         0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:10050                      0.0.0.0:*           
LISTEN         0              128                          0.0.0.0:10051                      0.0.0.0:*           
LISTEN         0              128                        127.0.0.1:9000                       0.0.0.0:*           
LISTEN         0              128                                *:80                               *:*           
LISTEN         0              128                             [::]:22                            [::]:*           
LISTEN         0              100                            [::1]:25                            [::]:*           
LISTEN         0              80                                 *:3306                             *:*           
[root@zabbix ~]# cd /usr/local/share/zabbix/alertscripts/
[root@zabbix alertscripts]# vim sendmail.sh
[root@zabbix alertscripts]# chmod +x sendmail.sh
[root@zabbix alertscripts]# su - zabbix -s /bin/bash
su: warning: cannot change directory to /home/zabbix: No such file or directory
[zabbix@zabbix alertscripts]$ /usr/local/share/zabbix/alertscripts/sendmail.sh yanchuanglol@163.com "123456" "test2"

本地邮箱脚本告警配置

添加媒介
Administration --- Media types --- 新建一个媒介

添加媒介信息

设置收件人
Administration --- Users --- Admin

设置动作
Configuration --- Actions --- 新建一个动作

触发验证

[root@yc2 ~]# echo 'send Email' >> /tmp/abc

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

第三方邮箱网页告警脚本告警配置
配置mail.rc
SMTP的主要配置如下:

set smtp=smtps://smtp.xxx.com:465   # 这里填入smtp地址
set smtp-auth=login                 # 认证方式
set smtp-auth-user=user@xxx.com     # 这里输入邮箱账号
set smtp-auth-password=password     # 这里填入密码
set ssl-verify=ignore               # 忽略证书警告
set nss-config-dir=/etc/pki/nssdb   # 证书所在目录
set from=user@xxx.com               # 设置发信人邮箱和昵称
#set smtp-use-starttls=yes          # STARTTLS时使用

文件默认在/etc/mail.rc下

//配置mail.rc
[root@zabbix ~]# vim /etc/mail.rc
#在最后一行添加如下信息
set smtp=smtp.126.com
set smtp-auth=login
set smtp-auth-user=yueshen233@126.com
set smtp-auth-password=XXXXXXXXXXXXX		#这里为授权码
set from=yuesheng233@126.com

第三方邮箱脚本告警配置
添加媒介
Administration --- Media types --- 新建一个媒介

添加媒介信息

设置收件人
Administration --- Users --- Admin

设置动作
Configuration --- Actions --- 新建一个动作

触发媒介

[root@yc2 ~]# echo 'send Email' >> /tmp/abc

验证

原文地址:https://www.cnblogs.com/Ycqifei/p/14711569.html