doubiao1734 2012-06-05 16:00
浏览 57
已采纳

使用PHP解析SNMP响应

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?


UPDATE:

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 ...

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配