续我的上篇博文:https://mp.csdn.net/postedit/88550212
一.qq邮箱报警装置
1、设置虚拟机可以连接上网;
##物理机
[root@foundation83 Desktop]# iptables -t nat -I POSTROUTING -s 172.25.83.0/24 -j MASQUERADE
##server1
[root@server1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.25.83.1
PREFIX=24
GATEWAY=172.25.83.83 #设置网关地址
DNS1=114.114.114.114 #设置DNS域名解析
[root@server1 ~]# ping www.baidu.com #测试网络是否ok
PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data.
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=1 ttl=50 time=23.0 ms
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=2 ttl=50 time=23.7 ms
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=3 ttl=50 time=35.0 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 23.070/27.307/35.090/5.513 ms
2、查看25端口是否存在(25端口是用来发送邮件的端口)
[root@server1 ~]# netstat -antulpe | grep 25
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 0 15289 827/master
3、在server1上安装mailx软件,以方便后续的实验
[root@server1 ~]# yum install mailx -y #安装mailx软件
#下面介绍mail的基本用法
[root@server1 ~]# mail root #给root用户发送邮件
Subject: test #发送的邮件的主题
hello world #发送的邮件的正文
EOT #发送结束之后,按"Ctrl + d"退出
[root@server1 ~]# mailq #查看邮件队列
Mail queue is empty
You have mail in /var/spool/mail/root
[root@server1 ~]# mail #查看发送的邮件的内容
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 root Fri Mar 15 15:56 18/594 "test" #显示只有一封邮件,邮件号是1
& 1 #输入邮件号:1
Message 1:
From [email protected] Fri Mar 15 15:56:11 2019 #什么时间发送的,以什么身份发送的
Return-Path: <[email protected]>
X-Original-To: root
Delivered-To: [email protected]
Date: Fri, 15 Mar 2019 15:56:11 +0800
To: [email protected]
Subject: test #发送的文件的主题
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R
hello world #发送的文件的内容
&
3、登陆qq邮箱,进入设置,进入反垃圾界面,设置白名单
二.onealert报警装置
1、设置虚拟机可以连接上网;
##物理机
[root@foundation83 Desktop]# iptables -t nat -I POSTROUTING -s 172.25.83.0/24 -j MASQUERADE
##server1
[root@server1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.25.83.1
PREFIX=24
GATEWAY=172.25.83.83 #设置网关地址
DNS1=114.114.114.114 #设置DNS域名解析
[root@server1 ~]# ping www.baidu.com #测试网络是否ok
PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data.
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=1 ttl=50 time=23.0 ms
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=2 ttl=50 time=23.7 ms
64 bytes from 220.181.112.244 (220.181.112.244): icmp_seq=3 ttl=50 time=35.0 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 23.070/27.307/35.090/5.513 ms
2、登陆onleart官网(网址是:http://www.onealert.com/),免费注册帐号;登陆,添加应用zabbix,并获取key;并设置通知策略
因为其中设置了,微信通知,所以需要手动绑定微信
3、安装onelitsm软件到脚本目录zabbix下:(可以查看技术文档:http://wiki.onealert.com/integration/zabbix-new.html)
下载OneITSM agent包:oneitsm_zabbix_release-1.2.0.tar.gz,并解压、安装。
[root@server1 ~]# tar zxf oneitsm_zabbix_release-1.2.0.tar.gz -C /usr/lib/zabbix/alertscripts/
[root@server1 ~]# cd /usr/lib/zabbix/alertscripts/
[root@server1 alertscripts]# ls
oneitsm
[root@server1 alertscripts]# cd oneitsm/bin/
[root@server1 bin]# ls
alert.sh install.sh log.sh update.sh
[root@server1 bin]# ./install.sh 50db7334-4596-8090-0bbe-9437940824ca
./log.sh: line 6: /usr/lib/zabbix/alertscripts/oneitsm/bin/oneitsm.conf: No such file or directory
start to create config file...
Zabbix管理地址: http://172.25.83.1/zabbix #这里输入Zabbix管理地址
Zabbix管理员账号: Admin #这里输入Zabbix管理员帐号
Zabbix管理员密码: #这里输入Zabbix管理员密码,初始默认的是zabbix,如果有修改,变为自定义的;
start to auth by zabbix admin user and password...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 195 100 70 100 125 860 1536 --:--:-- --:--:-- --:--:-- 1543
auth success!
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 109 100 41 100 68 786 1305 --:--:-- --:--:-- --:--:-- 1333
start to create mediatype...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 356 100 56 100 300 722 3870 --:--:-- --:--:-- --:--:-- 3896
create media type success!
start to create user group...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 214 100 54 100 160 679 2013 --:--:-- --:--:-- --:--:-- 2025
create user group success!
start to create user in zabbix...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 623 100 51 100 572 621 6966 --:--:-- --:--:-- --:--:-- 7061
create user success!
start to create action...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2013 100 51 100 1962 566 21791 --:--:-- --:--:-- --:--:-- 22044
create action success!
安装成功.
注:在安装过程中根据安装提示,输入zabbix管理/监控/web登陆地址、管理员用户名、密码
当提示"安装成功"时表示安装成功!
注:查看脚本目录zabbix的方法:
[root@server1 ~]# vim /etc/zabbix/zabbix_server.conf
4、浏览器设置报警:
(1)管理——>报警媒介类型:停用除了oneitsm之外的所有媒介;
(2)管理——>报警媒介类型——>oneitsm media:查看报警媒介的设置;(这步可做,可不做。只是查看,并没有修改任何内容)
(3)配置——>动作——>事件源(触发器)——>oneitsm action:查看报警媒介的动作;(这步可做,可不做。只是查看,并没有修改任何内容)
值的注意的是:oneitsm action显示的是“已启用”
问题发生时,发送的邮件的设置(标题,内容)
问题解决时,发送的邮件的设置(标题,内容)
4.测试:
在server2端停掉zabbix-agent服务(制造问题)
[root@server2 ~]# systemctl stop zabbix-agent
然后在微信查看是否收到警告信息;(这是源于之前的通知策略的设置)
在微信上点击认领
此时,微信上,也会收到认领信息
在server2端打开zabbix-agent服务(解决问题)
[root@server2 ~]# systemctl start zabbix-agent
然后在微信查看是否收到关闭信息;(这是源于之前的通知策略的设置)