一、网络发现
网络发现是zabbix最具特色的功能之一,它能能够根据用户事先定义的规则自动添加监控主机或服务等,Zabbix的网络发现功能可以基于:IP ranges、Availability of external services(FTP、SSH、WEB、POP3、IMAP、TCP、etc)、Information recevived from zabbix agent、Information recevived from SNMP agent.
网络发现通常包含两个阶段:discovery和actions
Discovery中的事件:
Service Up
Service Down
Host Up
Host Down
Service Discovered
Service Lost
Host Discovered
Host Lost
Action,网络发现中的事件可以触发action,从而自动执行指定的操作,如:
Sending notifications
Adding/removing hosts
Enabling/disabling hosts
Adding hosts to group
Removing hosts from a group
Linking hosts to/unlinking from a template
Executing remote scripts
二、自动注册
Zabbix支持active agent的自动注册(auto-resisitration)功能,通常用于此前故障的agent重新上线的场景,也可基于active agent的自动注册机制添加被动检测,这会通过active agent注册时提供的"ListenIP"和"ListenPort"进行,Server端在收到自动注册请求后以接收到的IP和Port为接口属性。
实验环境
192.168.30.116 OS:CentOS 6.4 x86_64 zabbix_server.luojianlong.com
192.168.30.117 OS:CentOS 6.4 x86_64 node1.luojianlong.com
192.168.30.119 OS:CentOS 6.4 x86_64 node2.luojianlong.com
192.168.30.115 OS:CentOS 6.4 x86_64 node3.luojianlong.com
zabbix_server,zabbix_agent已经安装完成,并且启动
[root@zabbix_server ~]# netstat -anptl | grep zabbix tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 19539/zabbix_server tcp 0 0 192.168.30.116:36692 192.168.30.116:3306 ESTABLISHED 19567/zabbix_server tcp 0 0 192.168.30.116:36681 192.168.30.116:3306 ESTABLISHED 19569/zabbix_server tcp 0 0 192.168.30.116:36684 192.168.30.116:3306 ESTABLISHED 19576/zabbix_server tcp 0 0 192.168.30.116:36677 192.168.30.116:3306 ESTABLISHED 19559/zabbix_server tcp 0 0 192.168.30.116:36680 192.168.30.116:3306 ESTABLISHED 19566/zabbix_server tcp 0 0 192.168.30.116:36682 192.168.30.116:3306 ESTABLISHED 19570/zabbix_server tcp 0 0 192.168.30.116:54102 192.168.30.116:3306 ESTABLISHED 19547/zabbix_server tcp 0 0 192.168.30.116:36685 192.168.30.116:3306 ESTABLISHED 19572/zabbix_server tcp 0 0 192.168.30.116:58705 192.168.30.116:3306 ESTABLISHED 19546/zabbix_server tcp 0 0 192.168.30.116:58706 192.168.30.116:3306 ESTABLISHED 19544/zabbix_server tcp 0 0 192.168.30.116:36679 192.168.30.116:3306 ESTABLISHED 19563/zabbix_server tcp 0 0 192.168.30.116:53068 192.168.30.116:3306 ESTABLISHED 19543/zabbix_server tcp 0 0 192.168.30.116:36694 192.168.30.116:3306 ESTABLISHED 19541/zabbix_server tcp 0 0 192.168.30.116:36683 192.168.30.116:3306 ESTABLISHED 19574/zabbix_server tcp 0 0 192.168.30.116:54112 192.168.30.116:3306 ESTABLISHED 19548/zabbix_server tcp 0 0 :::10051 :::* LISTEN 19539/zabbix_server [root@node1 ~]# netstat -anplt | grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 26800/zabbix_agentd tcp 0 0 :::10050 :::* LISTEN 26800/zabbix_agentd
下面开始创建模板
为模板添加items
创建graph
下面定义discovery rules,发现地址范围为:192.168.30.110-120
超时时间为:120s
检测的key为:刚才在item中定义的net.if.in[eth0]
检测标准为: IP address
定义actions,Event source选择Discovery
定义发现action名称,发送消息,主题
定义Operations,添加类型为host,link到之前创建的模板
定义Conditions,Discovery rule必须为Linux in localnet,Discovery status为:Discovered
主机IP在:192.168.30.110-120内
定义移除action,只要探测失败,就移除主机
观察是发现3台主机
发现主机已经被自动添加监控,并链接至模板
测试,主机下线,看是否会被移除
[root@node1 ~]# service zabbix-agent stop Shutting down Zabbix agent: [ OK ] [root@node2 ~]# service zabbix-agent stop Shutting down Zabbix agent: [ OK ] [root@node3 ~]# service zabbix-agent stop Shutting down Zabbix agent: [ OK ]
发现主机被自动移除
测试,恢复上线
[root@node1 ~]# service zabbix-agent start Starting Zabbix agent: [ OK ] [root@node2 ~]# service zabbix-agent start Starting Zabbix agent: [ OK ] [root@node3 ~]# service zabbix-agent start Starting Zabbix agent: [ OK ]
发现3个主机已经恢复监控
下面创建web监控
首先,在192.168.30.115主机中定义application
然后创建 web senario
定义steps
下面查看图像
可以看到页面的响应速度和下载速度
创建web监控的trigger,表达式为主页最后一次的响应码不等于200就触发事件
模拟故障
[root@node1 ~]# killall -9 nginx
发现触发器生效