zabbix提供网络发现功能:network discovery
HTTP、ICMP、SSH、LDAP、TCP、SNMP、Telnet、Zabbix_zgent扫描指定网络内的主机;
一旦主机被发信,如何对其进行操作,将由action来决定;

LLD:Low Level Discovery

此二者的功能:
自动添加移除主机、将主机链接至模板或移除链接、添加监控项、将主机添加至分组、定义触发器、执行远程脚本;

网络发信有两个步骤:
discovery --> action
发信中的事件:
Service Discoveryd, Service Lost, Service Up, Service Down
Host Discovery, Host List, Host Up, Host Down

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

Network discovery
网络发信是zabbix最具有特色的功能之一,它能够根据用户事先定义的规则自动添加监控的主机或服务等
speed up Zabbix deployment
simplify administration
use Zabbix in rapidly changing environments without excessive administration
Zabbix的网络发现功能可基于如下信息进行
IP ranges
Availability of external services(FTP,SSH,WEB,POP3,IMAP,TCP,etc)
Information received from Zabbix agent
Information received from SNMP agent

网络发现:过程阶段
网络发现通常包含两个阶段:discovery和actions
Discovery
Zabbix periodically scans the IP ranges defined in network discovery rules
The frequency of the check is configurable for each rule individually
Each rule has a set of service checks defined to be performed for the IP range
Every check of a service and a host(IP) performed by the network discovery module generates a discovery event

网络发信:Discovery
Discovery中的事件
Zabbix监控(七)_第1张图片

网络发信:Action
Actions
网络发现中的事件可以出发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
这些事件的配置还可以基于设备的类型、IP、状态、上线/离线等进行配置

网络发现:接口添加
网络发现中添加主机时会自动创建interface
the service detected
例如,如果基于SNMP检测成功,则会创建SNMP接口
如果某服务同时响应给了agent和SNMP,则两种接口都会创建
如果同一种发现机制(如agent)返回了非唯一数据,则第一个接口被识别为默认,其它的为额外接口
即便是某主机开始时只有agent接口,后来又通过snmp发现了它,同样会为其添加额外的snmp接口
不同的主机如果返回了相同的数据,则第一个主机将被添加,余下的主机会被当做一个主机的额外接口

auto_registation:
Action Agent Auto-Registration

HostMetadata

支持使用agent(active)类型的item key;

    配置过程:
        (1) 定义agent端:
                ServerActive=
                    Server=
                    Hostname=
                    ListenIP= 设置本机某特定IP
                    ListenPort=
                    HostMetadata=
                    HostMetadataItem=item key, 一般使用system.uname

            (2) 配置action, 要求其事件来源为auto-registation

LLD:Low Level Discovery
自动发现特定变量的名称:
#IFNAME, $FSNMAE,
添加针对对变量的Items:

    返回值为JSON

Web监控
Zabbix还可以进行web站点的可用性检测
创建web监控需要先定义一个web方案(scenarios)
web方案包括一个或多个HTTP请求或"步骤(step)"
步骤(step)的执行过程按照预先定义的顺序进行执行
通过web监控可实现获取如下信息
整个web方案中的所有的步骤的平均下载速度
失败的步骤号
失败的报错信息
在web方案的具体步骤中,可以按需使用如下信息
该步骤的下载速度
回应时间
回应状态码
Zabbix可以检测获取到的HTML页面中是否包含预设的字符串,也可以实现登录和页面点击

Web监控:创建web方案
创建web方案的前提需要创建一个适用的应用(application)
可以在"Hosts"或"Templates"上创建应用
如果在"Templates"上创建应用,则需要将此"Templates"链接至要监控其web的主机上方能适用此"application"
Configuration --> Web
Zabbix监控(七)_第2张图片

定义steps:
可以定义多个step以实现监控多个页面

Web监控:查看web监控图像
Monitoring --> Web 或者 Monitoring --> Latest data

主机名称:node2.smoke.com
操作系统:CentOS 6.5
内核版本:2.6.32-504.el6.x86_64
网卡1:vmnet0 172.16.100.8
网卡2:vmnet8 dhcp

node3:linux-agent

[root@node3 ~]# hostname
node3.smoke.com
[root@node3 ~]# ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c7:68:35 brd ff:ff:ff:ff:ff:ff
    inet 172.16.100.8/24 brd 172.16.100.255 scope global eth0
    inet6 fe80::20c:29ff:fec7:6835/64 scope link
       valid_lft forever preferred_lft forever
3: eth1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:c7:68:3f brd ff:ff:ff:ff:ff:ff
    inet 192.168.243.150/24 brd 192.168.243.255 scope global eth1
    inet6 fe80::20c:29ff:fec7:683f/64 scope link
       valid_lft forever preferred_lft forever
[root@node3 ~]# ip route show
172.16.100.0/24 dev eth0  proto kernel  scope link  src 172.16.100.8
192.168.243.0/24 dev eth1  proto kernel  scope link  src 192.168.243.150
169.254.0.0/16 dev eth0  scope link  metric 1002
169.254.0.0/16 dev eth1  scope link  metric 1003
default via 192.168.243.2 dev eth1
[root@node3 ~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate time.nist.gov &> /dev/null
[root@node3 ~]# vim /etc/hosts
172.16.100.6   node1.smoke.com node1
172.16.100.7   node2.smoke.com node2
172.16.100.8   node3.smoke.com node3

安装agent:
node3:linux-agent

[root@node3 ~]# cd zabbix-2.4.5/
[root@node3 zabbix-2.4.5]# ls
zabbix-2.4.5-1.el6.x86_64.rpm               zabbix-proxy-pgsql-2.4.5-1.el6.x86_64.rpm    zabbix-web-2.4.5-1.el6.noarch.rpm
zabbix-agent-2.4.5-1.el6.x86_64.rpm         zabbix-proxy-sqlite3-2.4.5-1.el6.x86_64.rpm  zabbix-web-japanese-2.4.5-1.el6.noarch.rpm
zabbix-get-2.4.5-1.el6.x86_64.rpm           zabbix-sender-2.4.5-1.el6.x86_64.rpm         zabbix-web-mysql-2.4.5-1.el6.noarch.rpm
zabbix-java-gateway-2.4.5-1.el6.x86_64.rpm  zabbix-server-2.4.5-1.el6.x86_64.rpm         zabbix-web-pgsql-2.4.5-1.el6.noarch.rpm
zabbix-proxy-2.4.5-1.el6.x86_64.rpm         zabbix-server-mysql-2.4.5-1.el6.x86_64.rpm
zabbix-proxy-mysql-2.4.5-1.el6.x86_64.rpm   zabbix-server-pgsql-2.4.5-1.el6.x86_64.rpm
[root@node3 zabbix-2.4.5]# yum -y localinstall zabbix-2.4.5-1.el6.x86_64.rpm zabbix-agent-2.4.5-1.el6.x86_64.rpm zabbix-sender-2.4.5-1.el6.x86_64.rpm
[root@node3 zabbix-2.4.5]# vim /etc/zabbix/zabbix_agentd.conf
Server=172.16.100.6
ServerActive=172.16.100.6
Hostname=node3.smoke.com
EnableRemoteCommands=1
LogRemoteCommands=1

node2:Linux-agent
[root@node2 ~]# scp /etc/zabbix/zabbix_agentd.d/{mysql.conf,os.conf} [email protected]:/etc/zabbix/zabbix_agentd.d/

node3:Linux-agent

[root@node3 zabbix-2.4.5]# service zabbix-agent start
[root@node3 zabbix-2.4.5]# ss -tnl
State       Recv-Q Send-Q                                 Local Address:Port                                   Peer Address:Port
LISTEN      0      128                                               :::22                                               :::*
LISTEN      0      128                                                *:22                                                *:*
LISTEN      0      100                                              ::1:25                                               :::*
LISTEN      0      100                                        127.0.0.1:25                                                *:*
LISTEN      0      128                                               :::10050                                            :::*
LISTEN      0      128                                                *:10050                                             *:*

点击Configuration -- Discovery -- Create discovery rule,填写完成点击Add;
Zabbix监控(七)_第3张图片

点击Monitoring -- Discovery,发现的主机;
Zabbix监控(七)

点击Configuration -- Templates -- Create template,点击Template菜单,填写完成点击Add;
Zabbix监控(七)_第4张图片

点击Linux server Memory Stats上的Applications -- Create application,填写完成点击Add;
Zabbix监控(七)

点击Linux server Memory Stats上的Items -- Create item,填写完成点击Add;
Zabbix监控(七)_第5张图片

继续点击Create item,填写完成点击Add;
Zabbix监控(七)_第6张图片

点击Linux server Memory Stats上的Graphs -- Create graph,点击Graph菜单,填写完成点击Add;
Zabbix监控(七)_第7张图片

点击Configuration -- Actions,Event source选择Discovery,点击Action菜单;
Zabbix监控(七)_第8张图片

点击Conditions菜单;
Zabbix监控(七)_第9张图片

点击Operations菜单,填写完成点击Add;
Zabbix监控(七)_第10张图片

node1:zabbix-server

[root@node1 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 324164
Server version: 10.0.10-MariaDB-log Source distribution

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use zabbix;
Database changed
MariaDB [zabbix]> SHOW TABLES;

MariaDB [zabbix]> DESC items;

MariaDB [zabbix]> SELECT key_ From items;

MariaDB [zabbix]> \q
Bye

点击Configuration -- Discovery,点击Local Linux Servers,将使用ping改为zabbix agent,点击Update;
Zabbix监控(七)_第11张图片

node3:linux-agent

[root@node3 zabbix-2.4.5]# service zabbix-agent stop
[root@node3 zabbix-2.4.5]# service zabbix-agent start

点击Monitoring -- Graphs,Group选择test group,Host选择node3.smoke.com,Graph选择Memory Stats;
Zabbix监控(七)_第12张图片

点击Configuration -- Discovery,点击Local Linux Servers,修改IP range为172.16.100.8;
Zabbix监控(七)_第13张图片

点击Configuration -- Actions,点击Local Linux Server Discovered,点击Conditions菜单,修改Host IP为172.16.100.8;
Zabbix监控(七)_第14张图片

node4:Linux-agent

[root@node4 ~]# hostname
node4.smoke.com
[root@node4 ~]# ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
5: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:90:d0:92 brd ff:ff:ff:ff:ff:ff
    inet 172.16.100.9/24 brd 172.16.100.255 scope global eth0
    inet6 fe80::20c:29ff:fe90:d092/64 scope link
       valid_lft forever preferred_lft forever
6: eth2:  mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:0c:29:90:d0:a6 brd ff:ff:ff:ff:ff:ff
7: eth1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:90:d0:9c brd ff:ff:ff:ff:ff:ff
    inet 192.168.243.151/24 brd 192.168.243.255 scope global eth1
    inet6 fe80::20c:29ff:fe90:d09c/64 scope link
       valid_lft forever preferred_lft forever
[root@node4 ~]# ip route show
172.16.100.0/24 dev eth0  proto kernel  scope link  src 172.16.100.9
192.168.243.0/24 dev eth1  proto kernel  scope link  src 192.168.243.151
169.254.0.0/16 dev eth0  scope link  metric 1005
169.254.0.0/16 dev eth1  scope link  metric 1007
default via 192.168.243.2 dev eth1
[root@node4 ~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate time.nist.gov &> /dev/null
[root@node4 ~]# vim /etc/hosts
172.16.100.6   node1.smoke.com node1
172.16.100.7   node2.smoke.com node2
172.16.100.8   node3.smoke.com node3
172.16.100.9   node4.smoke.com node4

安装linux-agent:
node4:linux-agent

[root@node4 ~]# cd zabbix-2.4.5/
[root@node4 zabbix-2.4.5]# yum -y localinstall zabbix-2.4.5-1.el6.x86_64.rpm zabbix-agent-2.4.5-1.el6.x86_64.rpm zabbix-sender-2.4.5-1.el6.x86_64.rpm
[root@node4 zabbix-2.4.5]# vim /etc/zabbix/zabbix_agentd.conf
Server=172.16.100.6
ServerActive=172.16.100.6
Hostname=node4.smoke.com
ListenIP=172.16.100.9
HostMetadata=artest
[root@node4 zabbix-2.4.5]# service zabbix-agent start
[root@node4 zabbix-2.4.5]# ss -tnl
State       Recv-Q Send-Q                                 Local Address:Port                                   Peer Address:Port
LISTEN      0      128                                               :::22                                               :::*
LISTEN      0      128                                                *:22                                                *:*
LISTEN      0      128                                     172.16.100.9:10050    
                                      *:*

node2:linux-agent

[root@node2 ~]# scp /etc/zabbix/zabbix_agentd.d/{mysql.conf,os.conf} [email protected]:/etc/zabbix/zabbix_agentd.d/

node4:linux-agent
[root@node4 zabbix-2.4.5]# service zabbix-agent restart

点击Configuration -- Action,Event source选择Auto registration,点击Create action,点击Action菜单;
Zabbix监控(七)_第15张图片

点击Conditions菜单;
Zabbix监控(七)_第16张图片

点击Operations菜单;
Zabbix监控(七)_第17张图片

点击Configuration -- Hosts,node4已经上线,并且被监控;
Zabbix监控(七)

在node4主机上点击Items -- Create item,添加完成点击Add;
Zabbix监控(七)_第18张图片

node1:zabbix-server

[root@node1 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 405722
Server version: 10.0.10-MariaDB-log Source distribution

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use zabbix;
Database changed
MariaDB [zabbix]> SELECT key_ FROM items WHERE key_ LIKE '%discovery%';
+---------------------------------------------------+
| key_                                              |
+---------------------------------------------------+
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| vfs.fs.discovery                                  |
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| net.if.discovery                                  |
| vfs.fs.discovery                                  |
| vmware.cluster.discovery[{$URL}]                  |
| vmware.hv.discovery[{$URL}]                       |
| vmware.vm.discovery[{$URL}]                       |
| vmware.vm.net.if.discovery[{$URL},{HOST.HOST}]    |
| vmware.vm.vfs.dev.discovery[{$URL},{HOST.HOST}]   |
| vmware.vm.vfs.fs.discovery[{$URL},{HOST.HOST}]    |
| vmware.hv.datastore.discovery[{$URL},{HOST.HOST}] |
+---------------------------------------------------+
24 rows in set (0.01 sec)

点击Configuration -- Templates,在Linux Server Memory Stats上点击Discovery -- Create discovery rule,点Discovery rule菜单;
Zabbix监控(七)_第19张图片

点击Configuration -- Hosts,点击node2上面点击Applications -- Create application,填写完成点击Add;
Zabbix监控(七)_第20张图片

点击Configuration -- Hosts,点击node2上面点击Web -- Create scenario,点击Scenario菜单;
Zabbix监控(七)_第21张图片

点击Steps菜单;
Zabbix监控(七)_第22张图片

点击Authentication菜单,认证为None,点击Add;
Zabbix监控(七)_第23张图片

点击Monitoring -- Latest data,在node2上面找到web sceinario,点击Graph;
Zabbix监控(七)_第24张图片