【问题标题】:pysnmp throwing UnknownCommunityName errorpysnmp 抛出 UnknownCommunityName 错误
【发布时间】:2016-01-13 15:48:02
【问题描述】:

我有一个包含 4 个 SNMP 陷阱数据包的 pcap 文件。当我通过 pysnmp 重放数据包时,它会抛出错误为

DBG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2023248>}

我已将 PySNMP 配置为接受社区名称为“公共”的数据包。

config.addV1System(snmpEngine, 'agent', 'public')

当我在 WireShark 中看到数据包时,它显示社区名称为 public,但通过 PySNMP 调试我发现社区名称在 OctetString 中(相当于 ASCII 中的 public)。我现在该怎么办?

附言Unix 的 snmptrapd 在给定的 pcap 文件中正常工作。

Pysnmp 版本:4.3.1
Pyasn1 版本:0.1.9

编辑 这是调试模式下的完整堆栈跟踪

2016-01-12_04:45:45.42174 2016-01-12 04:45:45,421 pysnmp: handle_read: transportAddress ('192.168.2.17', 162) -> ('0.0.0.0', 162) incomingMessage (70 octets) 
2016-01-12_04:45:45.42179 00000: 30 82 00 42 02 01 00 04 07 70 75 62 6C 69 63 00 
2016-01-12_04:45:45.42179 00016: A4 34 06 08 2B 06 01 04 01 90 7A 01 40 04 0A 62 
2016-01-12_04:45:45.42180 00032: 21 64 02 01 03 02 01 00 43 04 54 10 5A 06 30 16 
2016-01-12_04:45:45.42180 00048: 30 82 00 12 06 0D 2B 06 01 04 01 90 7A 01 02 01 
2016-01-12_04:45:45.42181 00064: 01 01 02 02 01 02
2016-01-12_04:45:45.42182 DEBUG: handle_read: transportAddress ('192.168.2.17', 162) -> ('0.0.0.0', 162) incomingMessage (70 octets) 
2016-01-12_04:45:45.42182 00000: 30 82 00 42 02 01 00 04 07 70 75 62 6C 69 63 00 
2016-01-12_04:45:45.42183 00016: A4 34 06 08 2B 06 01 04 01 90 7A 01 40 04 0A 62 
2016-01-12_04:45:45.42183 00032: 21 64 02 01 03 02 01 00 43 04 54 10 5A 06 30 16 
2016-01-12_04:45:45.42183 00048: 30 82 00 12 06 0D 2B 06 01 04 01 90 7A 01 02 01 
2016-01-12_04:45:45.42184 00064: 01 01 02 02 01 02
2016-01-12_04:45:45.42369 2016-01-12 04:45:45,423 pysnmp: receiveMessage: msgVersion 0, msg decoded
2016-01-12_04:45:45.42381 DEBUG: receiveMessage: msgVersion 0, msg decoded
2016-01-12_04:45:45.42587 2016-01-12 04:45:45,425 pysnmp: prepareDataElements: Message:
2016-01-12_04:45:45.42598  version='version-1'
2016-01-12_04:45:45.42606  community=0x7075626c696300
2016-01-12_04:45:45.42614  data=PDUs:
2016-01-12_04:45:45.42621   trap=TrapPDU:
2016-01-12_04:45:45.42628    enterprise=1.3.6.1.4.1.2170.1
2016-01-12_04:45:45.42636    agent-addr=NetworkAddress:
2016-01-12_04:45:45.42643     internet=10.98.33.100
2016-01-12_04:45:45.42650 
2016-01-12_04:45:45.42657    generic-trap='linkUp'
2016-01-12_04:45:45.42664    specific-trap=0
2016-01-12_04:45:45.42673    time-stamp=1410357766
2016-01-12_04:45:45.42683    variable-bindings=VarBindList:
2016-01-12_04:45:45.42685     VarBind:
2016-01-12_04:45:45.42685      name=1.3.6.1.4.1.2170.1.2.1.1.1.2
2016-01-12_04:45:45.42686      value=ObjectSyntax:
2016-01-12_04:45:45.42686       simple=SimpleSyntax:
2016-01-12_04:45:45.42686        number=2
2016-01-12_04:45:45.42687 
2016-01-12_04:45:45.42687 
2016-01-12_04:45:45.42688 
2016-01-12_04:45:45.42688 
2016-01-12_04:45:45.42689 
2016-01-12_04:45:45.42697 
2016-01-12_04:45:45.42697 DEBUG: prepareDataElements: Message:
2016-01-12_04:45:45.42698  version='version-1'
2016-01-12_04:45:45.42698  community=0x7075626c696300
2016-01-12_04:45:45.42699  data=PDUs:
2016-01-12_04:45:45.42699   trap=TrapPDU:
2016-01-12_04:45:45.42699    enterprise=1.3.6.1.4.1.2170.1
2016-01-12_04:45:45.42700    agent-addr=NetworkAddress:
2016-01-12_04:45:45.42700     internet=10.98.33.100
2016-01-12_04:45:45.42701 
2016-01-12_04:45:45.42701    generic-trap='linkUp'
2016-01-12_04:45:45.42701    specific-trap=0
2016-01-12_04:45:45.42702    time-stamp=1410357766
2016-01-12_04:45:45.42702    variable-bindings=VarBindList:
2016-01-12_04:45:45.42703     VarBind:
2016-01-12_04:45:45.42703      name=1.3.6.1.4.1.2170.1.2.1.1.1.2
2016-01-12_04:45:45.42710      value=ObjectSyntax:
2016-01-12_04:45:45.42720       simple=SimpleSyntax:
2016-01-12_04:45:45.42720        number=2
2016-01-12_04:45:45.42721 
2016-01-12_04:45:45.42721 
2016-01-12_04:45:45.42721 
2016-01-12_04:45:45.42722 
2016-01-12_04:45:45.42722 
2016-01-12_04:45:45.42723 
2016-01-12_04:45:45.42724 2016-01-12 04:45:45,426 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42731 DEBUG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42734 2016-01-12 04:45:45,426 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}
2016-01-12_04:45:45.42735 DEBUG: StatusInformation: {'errorIndication': <pysnmp.proto.errind.UnknownCommunityName instance at 0x2ce9680>}

只有一个代理存在问题。来自所有其他代理的陷阱正常处理。

【问题讨论】:

  • 您观察到的 OctetString 对象应该可以工作。确保您使用的是最新的 pysnmp。我怀疑它与“运输标签”有关。调试输出可能有助于解决此问题。
  • @llya Etingof 我已经用日志视图更新了我的问题。你能说一下看到调试日志的问题吗??
  • 我也升级了 pysnmp 到最新的稳定版本。

标签: pysnmp


【解决方案1】:

显然,当您从转储 (?) 数据包构建 PDU 时,您在 SNMP 社区字符串值中包含尾随零。

>>> from pysnmp.proto.rfc1902 import *
>>> OctetString(hexValue='7075626c696300').asOctets()
'public\x00'

如果这是您想要的,请确保相应地配置 pysnmp。

config.addV1System(snmpEngine, 'agent', 'public\x00')

config.addV1System(snmpEngine, 'agent', OctetString(hexValue='7075626c696300'))

【讨论】:

  • 太棒了!!代理本身正在发送带有训练零的社区字符串的陷阱。你拯救了我的一天:)
猜你喜欢
  • 2012-02-19
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 2015-03-24
  • 2011-12-27
  • 2018-08-06
  • 2011-10-17
相关资源
最近更新 更多