zabbix邮箱告警配置

zabbix邮箱告警配置

环境准备

服务ip主机名
服务端192.168.87.129server
客户端192.168.87.133agent
1.关闭防火墙和selinux
服务端
[root@server ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@server ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

客户端
[root@agent ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[root@agent ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

2.设置主机名

[root@server ~]# hostnamectl set-hostname server.example.com
[root@server ~]# bash
[root@server ~]# hostname
server.example.com


[root@agent ~]# hostnamectl set-hostname agent.example.com
[root@agent ~]# bash
[root@agent ~]# hostname
agent.example.com

3.修改配置文件/etc/hosts

[root@server ~]# vim /etc/hosts 
[root@server ~]# cat /etc/hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.87.129 server.example.com server
192.168.87.133 agent.example.com  agent


[root@agent yum.repos.d]# vim /etc/hosts
[root@agent yum.repos.d]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.87.129 server.example.com  server
192.168.87.133 agent.example.com agent

3、安装postfix软件

[root@server ~]# yum install -y postfix

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

[root@server ~]# vim /etc/postfix/main.cf

mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
(找到配置信息在后添加$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.

5.创建用户生成邮箱安装

[root@server ~]# useradd zhengbichao
[root@server ~]# ls /home/
zhengbichao
[root@server ~]# cd /var/spool/mail/
[root@server mail]# ll
total 0
-rw-rw---- 1 zhengbichao mail 0 Sep  5 11:18 zhengbichao
[root@server ~]# yum install -y mailx

一、第三方邮箱

1.注册163邮箱
2.开启SMTP服务和POP3服务,会生成一个授权码,需要记住这个授权码
在这里插入图片描述

3、修改报警媒介类型–email
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
4.配置动作
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

测试效果一

在这里插入图片描述
在这里插入图片描述

去到163邮箱查看
在这里插入图片描述

测试效果二

在这里插入图片描述

如图测试agent连接超过七个时是否还会发送邮箱

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

在这里插入图片描述

去到163邮箱查看
在这里插入图片描述

当连接数恢复到小于七个时

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

在这里插入图片描述

查看163邮箱
在这里插入图片描述

二、第三方邮箱+脚本

1.改mailx配置文件

[root@server ~]# vim /etc/mail.rc
在文件末尾添加
set from=zbc2992554169@163.com
set smtp=smtp.163.com
set smtp-auth-user=zbc2992554169@163.com
set smtp-auth-password=IZJKSIFSYZUCHZHR 
set smtp-auth=login
set ssl-verify=ignore


[root@server ~]# id zabbix
uid=993(zabbix) gid=990(zabbix) groups=990(zabbix)
[root@server ~]# chown -R zabbix.zabbix /etc/mail.rc 

2.在zabbix服务端写邮件发送脚本

[root@server alertscripts]# vim mail-send.sh
[root@server alertscripts]# cat 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 alertscripts]# chmod +x mail-send.sh 
[root@server alertscripts]# chown -R zabbix.zabbix mail-send.sh 
[root@server alertscripts]# ll
total 4
-rwxr-xr-x 1 zabbix zabbix 130 Sep  5 12:40 mail-send.sh

3.测试邮箱能否接收邮件

[root@server alertscripts]# ./mail-send.sh zbc2992554169@163.com "zabbix" "hello "

查看163邮箱
在这里插入图片描述

4.创建报警媒介类型
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

测试

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

在这里插入图片描述

查看163邮箱
在这里插入图片描述

当用户连接少于七个时检验

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

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Zabbix是一款开源的网络监控系统,可以用于监控各种网络设备、服务器和应用程序等。而钉钉是一款企业级即时通讯工具,可以用于实时通知和告警。在Zabbix配置钉钉告警可以实现在监控出现问题时通过钉钉发送告警消息给指定的用户或群组。 要配置Zabbix的钉钉告警,需要进行以下步骤: 1. 创建钉钉机器人:首先,在钉钉中创建一个机器人,用于接收Zabbix告警消息。在钉钉群组中找到机器人管理,创建一个自定义机器人,并获取到机器人的Webhook地址。 2. 在Zabbix配置媒介类型:登录到Zabbix的Web界面,进入“管理员”->“媒介类型”页面,点击“创建媒介类型”按钮。在弹出的对话框中填写相关信息,包括名称、类型、脚本名称等。类型选择“脚本”,脚本名称填写“zabbix-alertscript-dingtalk”,并在“脚本参数”中填写机器人的Webhook地址。 3. 配置告警动作:在Zabbix中进入“配置”->“动作”页面,点击“创建动作”按钮。在弹出的对话框中填写相关信息,包括名称、条件、操作等。在操作中选择“发送消息”,并选择之前创建的媒介类型。在“默认消息”中填写告警内容的模板,可以使用Zabbix的宏变量来动态替换相关信息。 完成以上配置后,当Zabbix监控到有问题时,就会通过钉钉机器人发送告警消息给指定的用户或群组。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

seven凡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值