一、第三方邮箱报警配置
报警
触发器的通知信息显示在web管理界面, 运维工程师仍然没办法24小时盯着它。所以我们希望它能自动地 通知工程师们,这就是报警。
zabbix的报警媒介支持email,jabber,sms(短信),微信,电话语音等。
报警过程原理
配置报警信息可以通过邮箱来实现
前期准备环境
1、确保server和agent1端的防火墙和selinux处于关闭状态
2、设置server端的主机名为server.example.com agent1端的主机名为agent1.example.com
3、分别修改server和agent1端的/etc/hosts文件
[root@server ~]# hostnamectl set-hostname server.example.com
[root@server ~]# bash
[root@server ~]# hostname
server.example.com
[root@server ~]# vim /etc/hosts
[root@server ~]# tail -2 /etc/hosts
192.168.47.137 server.example.com server
192.168.47.136 agent.example.com agent
//客户端
[root@agent ~]# hostnamectl set-hostname agent1.example.com
[root@agent ~]# bash
[root@agent1 ~]# hostname
agent1.example.com
[root@agent1 ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.47.137 server.example.com server
192.168.47.136 agent1.example.com agent
1、注册163邮箱
2、开启SMTP服务和POP3服务,会生成一个授权码,需要保存这个授权码
3、修改报警媒介类型–email
修改报警媒界类型
添加邮箱发送用户
成功
进入163邮箱进行查看
4、再次测试,客户端agent1连接数超过6个时,看163邮箱是否能收到邮件
查看触发器是否正常运行
已添加到七
[root@agent1 ~]# who | wc -l
7
[root@agent1 ~]#
这里的触发器缺乏动作(能指定报警信息传输在哪)
配置触发器动作
5、验证
Agent1端连接用户超过6个
当连接数少于6个的时候,修复好了,163邮箱会再次收到修复成功的邮件
二、第三方邮箱+脚本告警配置
1、下载邮件服务
[root@server alertscripts]# yum -y install postfix
[root@server alertscripts]# vim /etc/postfix/main.cf
修改邮件发送的的格式
//在该行后面加上$mydomain //调用自己的域名
mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
[root@server ~]# systemctl restart postfix.service
[root@server ~]# systemctl enable postfix.service
2、下载邮件发送服务,可以使用命令行的形式发送
[root@server ~]# yum -y install mailx
Last metadata expiration check: 1 day,
Installed:
mailx-12.5-29.el8.x86_64
Complete!
[root@server ~]# tail -8 /etc/mail.rc
# Add mail-conf by cy
set from=liutianyang0223@163.com
set smtp=smtp.163.com
set smtp-auth-user=liutianyang0223@163.com
set smtp-auth-passwor=CSPGTDLPWGPBBEPP //邮件密钥
set smtp-auth=login
set ssl-verify=ignore
//修改所属
[root@server ~]# ll /etc/mail.rc
-rw-r--r--. 1 root root 2172 Sep 5 11:38 /etc/mail.rc
[root@server ~]# chown zabbix.zabbix /etc/mail.rc
[root@server ~]# ll /etc/mail.rc
-rw-r--r--. 1 zabbix zabbix 2172 Sep 5 11:38 /etc/mail.rc
3、编写脚本
[root@server ~]# cd /usr/lib/zabbix/alertscripts/
[root@server alertscripts]# ls
[root@server alertscripts]# vim 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]# chown -R zabbix.zabbix mail-send.sh
[root@server alertscripts]# chmod +x mail-send.sh
[root@server alertscripts]# ll
total 4
-rwxr-xr-x. 1 zabbix zabbix 124 Sep 5 11:45 mail-send.sh
4、使用脚本发送邮件
[root@server alertscripts]# ./mail-send.sh liutianyang0223@163.com "test" "123"
基于脚本连接触发器报警
1、创建报警媒介类型
2、给用户添加邮箱
3、创建动作
4、验证–agent1连接数超过6个
修复好后,仍然可以接收邮件
本文含有隐藏内容,请 开通VIP 后查看