Reading SNMP Object index of type IPAddress

故事扮演 提交于 2019-12-22 11:28:12

问题


In a simple SNMP table like mib-2.interfaces.ifTable, ifIndex is the index for the table, so you read ifIndex.1 (i.e. read value from direct child nodes of ifIndex) to get the index for the first row of the table. Simple enough.

But it's not as obvious with something like mib-2.ip.ipRouteTable. In that case ipRouteIfIndex is the index column. It's defined as INTEGER just like ifIndex was. However, you can't read the direct child nodes (i.e. ifIndex.0 is a direct child), but instead need to read ifIndex.0.0.0.0 to get to the value. So how does one know how to find the value when it's not a direct child of the index column?

There is some concept that I'm not understanding. (Probably having to do with the fact that SNMP objects are delimited by . but so are IP addresses, and I can't tell how to recognize the difference).


回答1:


Note that you have a table with multiple indices in this particular case.

The fact is that you cannot directly read the table entries with snmp-get service, since the index is dynamic (and, as a consequence, the OID address). But you can discover the values with snmp-get-next (v1) and snmp-get-bulk (v2) services.

For example, you can read the indices (and store them for querying table items later) or directly read the items of the table :

  • you ask snmp-get-next for IP-MIB::ipAdEntNetMask
  • the reply will be IP-MIB::ipAdEntNetMask.172.16.38.42 IPV4 255.255.0.0
  • (So: first index is 172.16.38.42 in that case!)
  • you iterate and ask next value after IP-MIB::ipAdEntNetMask.172.16.38.42
  • the reply will be IP-MIB::ipAdEntNetMask.172.16.11.43 IPV4 255.255.0.0
  • etc.. until there is no other value, or the value is not on the same tree

The service snmp-get-bulk will enable you to query N values directly in this way.

Have a look at Net-Snmp's snmptable that does good job with tables : http://net-snmp.sourceforge.net/wiki/index.php/TUT:snmptable



来源:https://stackoverflow.com/questions/12438363/reading-snmp-object-index-of-type-ipaddress

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!