2012-06-05 16:00
浏览 56


I'm currently successfully reading out several properties on our switches over SNMP with php. Now i'm looking at making the resulting output of snmpget and snmpwalk actually usefull for the consumers of our API's.

Problem is that the responses look like this: INTEGER: up(1) and INTEGER: 10103 ...

Is there any convention/standard on how to parse this response format or is the response vendor specific for each device we are trying to read?

Is there by any chance already a PHP library, function or extension that can cast these responses in php native variables or at least something usefull that we can work with?


I've found out a few new things namely that there are indeed several libraries in php that can parse binary ASN.1 strings which basically are BER encoded strings if i'm right. Problem is that i can't seem to find a way to get the binary data from the devices with php ...

图片转代码服务由CSDN问答提供 功能建议

我目前正在使用php成功读取我们的SNMP交换机上的几个属性。 现在我正在考虑使 snmpget snmpwalk 的结果输出对我们API的消费者有用。

问题是 响应如下所示: INTEGER:up(1) INTEGER:10103 ...

是否有任何约定/ 关于如何解析这种响应格式的标准,还是我们试图读取的每个设备的特定响应供应商?

是否有任何机会已经可以转换的PHP库,函数或扩展 php本机变量中的这些响应或者至少是我们可以使用的有用的东西?


我' 我发现了一些新的东西,即php中确实有几个库可以解析二进制ASN.1字符串,如果我是正确的话,它基本上是BER编码的字符串。 问题是我似乎找不到用php从设备中获取二进制数据的方法......

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dooo61733 2012-06-08 07:55

    I'm not sure about your particular PHP methods, but the difference between your two INTEGER examples is likely to be whether your system has an SNMP MIB corresponding to the OID (e.g. to determine that 1 means "up").

    If you only want the integers, you should be able to pass a parameter to your get or walk command. For example, net-snmp's snmpget or snmpwalk commands will take -Oe to remove symbolic labels. From the manpage:

                  $ snmpget -c public -v 1 localhost ipForwarding.0
                  IP-MIB::ipForwarding.0 = INTEGER: forwarding(1)
                  $ snmpget -c public -v 1 -Oe localhost ipForwarding.0
                  IP-MIB::ipForwarding.0 = INTEGER: 1

    If you are parsing net-snmp output, I recommend reading the snmpcmd man page as it has a lot of output options that will interest you especially the display of other types such as timeticks and strings.

    If you do want to retrieve SNMP in PHP you could look at how Cacti does it.

    解决 无用
    打赏 举报

相关推荐 更多相似问题