zabbix Server 4.0 触发器(Trigger)篇
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.触发器(Trigger)概述
1>.上一篇博客我们介绍了“内置item使用案例”,item(监控项)仅负责收集数据,而通常收集数据的目的还包括在某指标对应的数据超出合理范围时给先关人员发送告警信息,“触发器”正是用于为监控项所收集的数据定义阈值。
2>.每一个触发器仅能关联至一个监控项,但可以为一个监控项同时使用多个触发器(事实上,为一个监控项预定义多个具有不同阈值的触发器,可以实现不同级别的报警功能)。
3>.一个触发器由一个表达式构成,它定义了监控项所采取的数据的一个阈值,一旦某次采集超出了此触发器定义的阈值,触发器状态将会转换为“Problem”;而当采取的数据再次回归至合理范围内时,其状态将重新返回到“OK”。
二.触发器(Trigger)表达式
1>.触发器表达式高度灵活,可以以之创建出非常复杂的测试条件。
2>.基本的触发器表达式格式如下:
{
举个例子:
{node101.yinzhengjie.org.cn:system.cpu.load[all,avg1].last(0)}>3
上述案例表示主机"node101.yinzhengjie.org.cn"上所有CPU的过去1分钟内的平均负载和最后一次取值大于3时将触发状态变化。对last函数来说,last(0)相当于last(#1)。
三.触发器(Trigger)间的依赖关系
在一个网络中,主机的可用性之间可能存在依赖关系。如下图所示:
我们假设Zabbix Server和我们被监控的打印机,路由器等网络设备,服务器都连接到核心交换机上了,如果此时的核心交换宕机了(即该设备变得不可用),其背后的所有主机都无法正常访问。如果所有主机都配置了触发器并定义了相关通知功能,相关人员将会接收到许多告警信息,这既不利于快速定位问题,也会浪费资源。正确定义的触发器依赖关系可以避免类似情况的发生,它将使用通知机制仅发送最根本问题先关的告警。(也就是说我们合理定义了触发器的依赖关系,当核心交换机宕机时,并不会所有配置告警都触发,而是先判断核心交换机是否挂掉,把最精准的故障定位报出来!)
需要注意的是,目前zabbix不能够直接定义主机间的依赖关系,其依赖关系仅能通过触发器来定义。
四.触发器(Trigger)等级
触发器等级用于标识时间的严重性。zabbix支持以如下表 所示的等级。下图摘自官方网站:https://www.zabbix.com/documentation/4.0/manual/config/triggers/severity(中文链接戳我)。
五.创建触发器(Trigger)
1>.如下图所示,找到我们要定义触发器的主机
2>.点击Create trigger
3>.根据zabbix内置的选择器,我们根据匹配规则自动生成触发器表达式
4>.点击添加(注意下图只是配置Trigger页面,点击图中的“Dependencies”可以配置相应的依赖关系!)
5>.添加触发器成功
6>.查看主机配置,发现多出来一个触发器
7>.查看触发器相关信息
8>. 查看最新的数据
9>.查看item的Graph图形(如果有遇到中文乱码问题,可参考:https://www.cnblogs.com/yinzhengjie/p/10386196.html中的解决方案。)
六.模拟实验环境让触发器生效
1>.在zabbix server服务器发包到node102.yinzhengjie.org.cn主机上
[root@node101.yinzhengjie.org.cn ~]# yum -y install epel-release #安装epel源
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql56-community | 2.5 kB 00:00:00
updates | 3.4 kB 00:00:00
zabbix | 2.9 kB 00:00:00
zabbix-non-supported | 951 B 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency ResolutionDependencies Resolved======================================================================================================================================================================================Package Arch Version Repository Size
======================================================================================================================================================================================
Installing:epel-release noarch 7-11 extras 15 kTransaction Summary
======================================================================================================================================================================================
Install 1 PackageTotal download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm | 15 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : epel-release-7-11.noarch 1/1 Verifying : epel-release-7-11.noarch 1/1 Installed:epel-release.noarch 0:7-11 Complete!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# yum -y install hping3 #安装hping3工具包
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 6.8 kB 00:00:00 * base: mirrors.aliyun.com* epel: mirror.premi.st* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
epel | 4.7 kB 00:00:00
(1/3): epel/x86_64/group_gz | 88 kB 00:00:00
(2/3): epel/x86_64/updateinfo | 992 kB 00:00:03
(3/3): epel/x86_64/primary_db | 6.7 MB 00:00:06
Resolving Dependencies
--> Running transaction check
---> Package hping3.x86_64 0:0.0.20051105-24.el7 will be installed
--> Processing Dependency: libpcap.so.1()(64bit) for package: hping3-0.0.20051105-24.el7.x86_64
--> Processing Dependency: libtcl8.5.so()(64bit) for package: hping3-0.0.20051105-24.el7.x86_64
--> Running transaction check
---> Package libpcap.x86_64 14:1.5.3-11.el7 will be installed
---> Package tcl.x86_64 1:8.5.13-8.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved======================================================================================================================================================================================Package Arch Version Repository Size
======================================================================================================================================================================================
Installing:hping3 x86_64 0.0.20051105-24.el7 epel 96 k
Installing for dependencies:libpcap x86_64 14:1.5.3-11.el7 base 138 ktcl x86_64 1:8.5.13-8.el7 base 1.9 MTransaction Summary
======================================================================================================================================================================================
Install 1 Package (+2 Dependent packages)Total download size: 2.1 M
Installed size: 4.9 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/hping3-0.0.20051105-24.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for hping3-0.0.20051105-24.el7.x86_64.rpm is not installed
(1/3): hping3-0.0.20051105-24.el7.x86_64.rpm | 96 kB 00:00:00
(2/3): tcl-8.5.13-8.el7.x86_64.rpm | 1.9 MB 00:00:03
(3/3): libpcap-1.5.3-11.el7.x86_64.rpm | 138 kB 00:00:04
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 466 kB/s | 2.1 MB 00:00:04
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:Userid : "Fedora EPEL (7)
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : 1:tcl-8.5.13-8.el7.x86_64 1/3 Installing : 14:libpcap-1.5.3-11.el7.x86_64 2/3 Installing : hping3-0.0.20051105-24.el7.x86_64 3/3 Verifying : 14:libpcap-1.5.3-11.el7.x86_64 1/3 Verifying : 1:tcl-8.5.13-8.el7.x86_64 2/3 Verifying : hping3-0.0.20051105-24.el7.x86_64 3/3 Installed:hping3.x86_64 0:0.0.20051105-24.el7 Dependency Installed:libpcap.x86_64 14:1.5.3-11.el7 tcl.x86_64 1:8.5.13-8.el7 Complete!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# hping3 --faster node102.yinzhengjie.org.cn
HPING node102.yinzhengjie.org.cn (eth0 172.30.1.102): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=172.30.1.102 ttl=64 DF id=18150 sport=0 flags=RA seq=0 win=0 rtt=0.4 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18233 sport=0 flags=RA seq=1 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18250 sport=0 flags=RA seq=2 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18269 sport=0 flags=RA seq=3 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18302 sport=0 flags=RA seq=4 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18342 sport=0 flags=RA seq=5 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18396 sport=0 flags=RA seq=6 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18451 sport=0 flags=RA seq=7 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18465 sport=0 flags=RA seq=8 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18543 sport=0 flags=RA seq=9 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18583 sport=0 flags=RA seq=10 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18671 sport=0 flags=RA seq=11 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18762 sport=0 flags=RA seq=12 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18852 sport=0 flags=RA seq=13 win=0 rtt=0.3 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18921 sport=0 flags=RA seq=14 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=18975 sport=0 flags=RA seq=15 win=0 rtt=0.3 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19025 sport=0 flags=RA seq=16 win=0 rtt=0.3 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19115 sport=0 flags=RA seq=17 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19200 sport=0 flags=RA seq=18 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19226 sport=0 flags=RA seq=19 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19239 sport=0 flags=RA seq=20 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19313 sport=0 flags=RA seq=21 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19411 sport=0 flags=RA seq=22 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19487 sport=0 flags=RA seq=23 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19506 sport=0 flags=RA seq=24 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19598 sport=0 flags=RA seq=25 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19698 sport=0 flags=RA seq=26 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19781 sport=0 flags=RA seq=27 win=0 rtt=0.4 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19785 sport=0 flags=RA seq=28 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19805 sport=0 flags=RA seq=29 win=0 rtt=0.4 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19838 sport=0 flags=RA seq=30 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19904 sport=0 flags=RA seq=31 win=0 rtt=0.4 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19921 sport=0 flags=RA seq=32 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=19994 sport=0 flags=RA seq=33 win=0 rtt=0.2 ms
len=46 ip=172.30.1.102 ttl=64 DF id=20088 sport=0 flags=RA seq=34 win=0 rtt=0.2 ms
..........
2>.查看最新数据的流量图
3>.查看zabbix的Dashboard界面
七.item(监控项)可以定义多个触发器
1>.克隆我们之间的触发器,我们将触发器的值稍作修改
2>.修改触发器的值和触发器的名称
3>.重复上述步骤,我们可以再clone一个触发器,添加成功后,我们就会成功添加3个触发器
4>.查看item的触发器个数
5>.查看Graph图形
6>.查看Dashboard