如何通过MIB名称获取SNMP值?

时间:2013-02-26 12:37:22

标签: node.js snmp net-snmp

模拟bash:

snmpwalk -c SNMP1TV01 -v 2c 127.0.0.1 IF-MIB::ifName | grep bond0
IF-MIB::ifName.8 = STRING: bond0
snmpwalk -c SNMP1TV01 -v 2c 12.0.0.0.1 IF-MIB::ifHCOutOctets | grep 8
IF-MIB::ifHCOutOctets.8 = Counter64: 13775300423919 

我无法通过oid来实现,因为以太网接口经常更改

1 个答案:

答案 0 :(得分:1)

虽然我不熟悉node.js但它不能检索表,而不仅仅是走树的那一部分,例如

snmptable -M +.  -m +ALL -v 2c -c public -Pu -Ci 127.0.0.1 IF-MIB:ifXTable 
SNMP table: IF-MIB::ifXTable

index   ifName ifInMulticastPkts ifInBroadcastPkts ifOutMulticastPkts ifOutBroadcastPkts  ifHCInOctets ifHCInUcastPkts ifHCInMulticastPkts ifHCInBroadcastPkts ifHCOutOctets ifHCOutUcastPkts ifHCOutMulticastPkts ifHCOutBroadcastPkts ifLinkUpDownTrapEnable ifHighSpeed ifPromiscuousMode ifConnectorPresent ifAlias ifCounterDiscontinuityTime
1        lo                 0                 0                  0                  0 3675102238172      2759723359                   0                   0 3675102238172       2759723359                    0                    0                      ?          10             false                  ?                       0:0:00:00.00
2     bond0               959                 0                  0                  0   21395174710        43909149                 959                   0    5835176503         49589529                    0                    0                      ?        1000             false               true                       0:0:00:00.00

<not showing my other interfaces>

提取相关价值......

snmptable -M +.  -m +ALL -v 2c -c public -Pu -Ci 127.0.0.1     IF-MIB:ifXTable | grep bond0 | awk '{print $11}'
5835176503