zabbix服务配置邮箱告警(定义媒介、配置动作)
文章目录
监控流程
本地邮箱告警配置
第三方邮箱网页配置告警
1.首先我们要在服务端(zabbix_server)和客户端(zabbix_agnetd)上都安装邮件的工具,需要安装两个关于邮件的包,如下:
服务端:
[root@client src]# yum provides *bin/mailx
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:55:06 ago on Mon 25 Sep 2023 01:09:43 PM CST.
mailx-12.5-29.el8.x86_64 : Enhanced implementation of the mailx command
Repo : base
Matched from:
Other : *bin/mailx
s-nail-14.9.23-1.el8.x86_64 : Environment for sending and receiving mail
Repo : Everything
Matched from:
Provide : /bin/mailx
[root@client src]# yum -y install mailx
省略. . .
[root@client src]# yum provides *bin/sendmail
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:56:51 ago on Mon 25 Sep 2023 01:09:43 PM CST.
esmtp-1.2-15.el8.x86_64 : User configurable send-only Mail Transfer Agent
Repo : Everything
Matched from:
Other : *bin/sendmail
exim-4.96-5.el8.x86_64 : The exim mail transfer agent
Repo : Everything
Matched from:
Other : *bin/sendmail
opensmtpd-6.8.0p2-3.el8.x86_64 : Free implementation of the server-side SMTP protocol as defined by RFC 5321
Repo : Everything
Matched from:
Other : *bin/sendmail
postfix-2:3.5.8-2.el8.x86_64 : Postfix Mail Transport Agent
Repo : base
Matched from:
Other : *bin/sendmail
sendmail-8.15.2-34.el8.x86_64 : A widely used Mail Transport Agent (MTA)
Repo : AppStream
Matched from:
Other : *bin/sendmail
[root@client src]# yum -y install postfix
省略. . .
//开启发送邮件的服务,端口为25
[root@client src]# systemctl start postfix.service
[root@client src]# 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 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
客户端是上述同样的操作
[root@centos2 ~]# yum -y install mailx
[root@centos2 ~]# yum -y install postfix
[root@centos2 ~]# 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 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
测试邮件是否能正常发送到QQ邮箱
服务端:
[root@client src]# echo "hello world" | mail -s "这是一个测试文件" 2046807065@qq.com
客户端:
[root@centos2 ~]# ss -antlecho "hello world" | mail -s "这是一个测试文件" 2046807065@qq.com
以上只是我们以命令行的模式执行的,而我们需要达到让他本身能够发送邮件告警。
2.结合脚本让他自身去触发脚本,执行发送邮件告警
2.1本地邮箱告警配置,编写脚本
编写一个脚本,而这个脚本应该放在/usr/local/share/zabbix/alertscripts
下面
[root@client alertscripts]# vim sendmail.sh
[root@client alertscripts]# chmod +x sendmail.sh
[root@client alertscripts]# cat sendmail.sh
#!/bin/bash
content=$(echo $1 | tr "\r\n" "\n")
subject=$(echo $1 | tr "\r\n" "\n")
mailto=$3
echo $content | mail -s $subject $mailto
配置媒介
媒介定义成功
2.2配置动作(告知、处理)
2.3测试
此时媒介和动作都已经配置完成,我们借助先前在centos2主机上的/tmp/ftx文件来测试是否执行告警动作
[root@centos2 tmp]# echo "#" >> ftx
[root@centos2 tmp]# cat ftx
hello world
#
3第三方邮箱网页配置告警(利用真实邮箱发送告警)
3.1配置邮箱以及媒介
这里我们将第三方邮箱定为网易邮箱
收件邮箱还是我们的QQ邮箱
3.2测试
测试成功
测试成功
3.3配置触发动作
进入用户页面,将媒介改类型改为Email
3.4再次测试
添加一串内容,改变文件MD5值
[root@centos2 ~]# echo "123" >> /tmp/ftx
[root@centos2 ~]# cat /tmp/ftx
hello world
#
123