Version: zabbix 3.0.1
概述
Low-Level discovery 可以自动创建items,triggers,graphs为不同的实体对象。
例如:zabbix能自动监控服务器上的所有文件系统,网路接口。而不用手动在每个文件系统,网络接口上创建items。
除此之外,也可以根据discovery返回的结果,配置zabbix移除不需要的实体对象
zabbix支持六种不同的discovery items
discovery of file systems;
discovery of network interfaces;
discovery of CPUs and CPU cores;
discovery of SNMP OIDs;
discovery using ODBC SQL queries;
discovery of Windows services.
用户也可以自定义discovery,通过独有的JSON协议
1、用户定义discovery脚本
返回宏变量 例如:{#DEVICENAME} -> sda,{#DEVICENAME} -> sdb
2、创建prototypes
例如:custom.vfs.dev.io.active[{#DEVICENAME}]
以下是一般的自定义discovery处理结构
首先,创建discovery rule在”Configuration” → “Templates” → “Discovery“列
(discovery rule的组成(1)发现实体对象(列如:文件系统,网络接口) (2)prototypes:在之前发现的实体对象上创建items,triggers,graphs)
(1)
属性说明
Discovery rule
Keep lost resources period (in days) # 数据保留的天数
Filter
对返回的数据进行过滤筛选,支持regexp
(2)
lld-disks.py;chmod +x lld-disks.py
#!/usr/bin/env python '''
zabbix disks Low-Level discovery
''' import os
import re
import json def Devices(diskdir, skippable): raw_devices = (device for device in os.listdir(diskdir) if not any(ignore in device for ignore in skippable))
devices = (device for device in raw_devices if re.match(r'^\w{3}$', device)) # 保留整块磁盘 去掉分区, such as remove sda1 sdb2
data = [{"{#DEVICENAME}": device} for device in devices]
print(json.dumps({"data": data}, indent=)) if __name__ == "__main__":
# Iterate over all block devices, but ignore them if they are in the skippable set
diskdir = "/sys/class/block"
skippable = ("sr", "loop", "ram", "dm")
Devices(diskdir, skippable)
response # json格式
{
"data": [
{
"{#DEVICENAME}": "sdb"
},
{
"{#DEVICENAME}": "sda"
}
]
}