SNMP 原子性获取接口和计数器

huangapple go评论92阅读模式
英文:

SNMP atomically get interfaces and counters

问题

我有一些需要通过SNMP监控的交换机和路由器。交换机和路由器上的接口数量以及它们在OID中的“后缀”可能在任意时刻发生变化。

我如何原子地获取接口名称到OID后缀映射以及这些接口上感兴趣的计数器?

英文:

I have some switches and routers that should be monitored over SNMP. Number of interfaces in switches and routers and their "suffix" in OID can change at an arbitrary moment.

How can I atomically get both interface name to OID suffix mapping and interested counters on this interfaces?

答案1

得分: 1

一个SNMP的GET-NEXT请求可以同时查询表的多列。如果你想要查询,例如,ifInDiscardsifInErrors,还有ifDescr,只需一次性查询所有三者。在Shell中使用snmpgetnext可以这样做(snmpwalk似乎不支持这个功能):

snmpgetnext <参数> <主机IP> IF-MIB::ifDescr IF-MIB::ifInDiscards IF-MIB::ifInErrors

在我的机器上,输出如下:

IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifInDiscards.1 = Counter32: 0
IF-MIB::ifInErrors.1 = Counter32: 0

然后,你需要使用前面响应中的.1更新你的查询,以便获取下一个接口的结果:

snmpgetnext <参数> <主机IP> IF-MIB::ifDescr.1 IF-MIB::ifInDiscards.1 IF-MIB::ifInErrors.1
英文:

An SNMP GET-NEXT request can query multiple columns of a table at once. If you want, for example, the ifInDiscards and ifInErrors, along with the ifDescr, simply query for all three at once. Here's how to do it in the shell using snmpgetnext (snmpwalk doesn't appear to support this):

snmpgetnext &lt;parameters&gt; &lt;host-ip&gt; IF-MIB::ifDescr IF-MIB::ifInDiscards IF-MIB::ifInErrors

Here's the output on my machine:

IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifInDiscards.1 = Counter32: 0
IF-MIB::ifInErrors.1 = Counter32: 0

Then, you will have to update your query with the .1 from the previous response in order to get the results for the next interface:

snmpgetnext &lt;parameters&gt; &lt;host-ip&gt; IF-MIB::ifDescr.1 IF-MIB::ifInDiscards.1 IF-MIB::ifInErrors.1

huangapple
  • 本文由 发表于 2023年5月22日 18:27:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76305241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定