Zabbix SNMP OID discovery,自动发现

时间:2022-09-29 17:39:07

Unlike file system and network interface discovery, the item does not necessarily have to have “snmp.discovery” key - item type of SNMP agent is sufficient.

The OIDs to discover are defined in SNMP OID field in the following format: discovery[{#MACRO1}, oid1, {#MACRO2}, oid2, …,]

where {#MACRO1}{#MACRO2} … are valid lld macro names and oid1oid2… are OIDs capable of generating meaningful values for these macros. A built-in macro {#SNMPINDEX} containing index of the discovered OID is applied to discovered entities. The discovered entities are grouped by {#SNMPINDEX} macro value.

To understand what we mean, let us perform few snmpwalks on our switch:

$ snmpwalk -v 2c -c public 192.168.1.1 IF-MIB::ifDescr
IF-MIB::ifDescr.1 = STRING: WAN
IF-MIB::ifDescr.2 = STRING: LAN1
IF-MIB::ifDescr.3 = STRING: LAN2 $ snmpwalk -v 2c -c public 192.168.1.1 IF-MIB::ifPhysAddress
IF-MIB::ifPhysAddress.1 = STRING: 8:0:27:90:7a:75
IF-MIB::ifPhysAddress.2 = STRING: 8:0:27:90:7a:76
IF-MIB::ifPhysAddress.3 = STRING: 8:0:27:2b:af:9e

And set SNMP OID to: discovery[{#IFDESCR}, ifDescr, {#IFPHYSADDRESS}, ifPhysAddress]

Now this rule will discover entities with {#IFDESCR} macros set to WANLAN1 and LAN2, {#IFPHYSADDRESS} macros set to 8:0:27:90:7a:758:0:27:90:7a:76, and 8:0:27:2b:af:9e, {#SNMPINDEX} macros set to the discovered OIDs indexes 12 and 3:

{
"data": [
{
"{#SNMPINDEX}": "",
"{#IFDESCR}": "WAN",
"{#IFPHYSADDRESS}": "8:0:27:90:7a:75"
},
{
"{#SNMPINDEX}": "",
"{#IFDESCR}": "LAN1",
"{#IFPHYSADDRESS}": "8:0:27:90:7a:76"
},
{
"{#SNMPINDEX}": "",
"{#IFDESCR}": "LAN2",
"{#IFPHYSADDRESS}": "8:0:27:2b:af:9e"
}
]
}

If an entity does not have the specified OID, then the corresponding macro will be omitted for this entity. For example if we have the following data:

ifDescr. "Interface #1"
ifDescr. "Interface #2"
ifDescr. "Interface #4" ifAlias. "eth0"
ifAlias. "eth1"
ifAlias. "eth2"
ifAlias. "eth4"

Then in this case SNMP discovery discovery[{#IFDESCR}, ifDescr, {#IFALIAS}, ifAlias] will return the following structure:

{
"data": [
{
"{#SNMPINDEX}": ,
"{#IFDESCR}": "Interface #1",
"{#IFALIAS}": "eth0"
},
{
"{#SNMPINDEX}": ,
"{#IFDESCR}": "Interface #2",
"{#IFALIAS}": "eth1"
},
{
"{#SNMPINDEX}": ,
"{#IFALIAS}": "eth2"
},
{
"{#SNMPINDEX}": ,
"{#IFDESCR}": "Interface #4"
},
{
"{#SNMPINDEX}": ,
"{#IFALIAS}": "eth4"
}
]
}

建立snmp discovery 规则,SNMP OID:discovery[{#IFDESCR},IF-MIB::ifDescr],

意思就是 snmpget 所有 IF-MIB::ifDescr 的值存放在 #IFDESCR 这个Marco(宏)里面,按照 #SNMPINDEX=1,2,3 排列存储。

Zabbix SNMP OID discovery,自动发现

The following screenshot illustrates how we can use these macros in item prototypes:

创建 Item Prototypes规则,name里面的 $1 参数就是 key 里面传回的第一个参数,也就是 Discovery rule里面获得的 #IFDESCR 【对应#SNMPINDEX】的值。

返回的真实值就是:snmpget 的 SNMP OID 里面的IF-MIB::ifInOctets.{#SNMPINDEX}的值,SNMP community 对应的是添加主机时候设置的团体名。

Zabbix SNMP OID discovery,自动发现

当然也可以自己用snmpwalk命令一一指定要监控的某个具体的端口。