[英]Querying numerical OID in PySNMP?
I'm attempting to query an SNMP variable on a Cisco routing device in Python, and struggling. 我正在尝试用Python查询Cisco路由设备上的SNMP变量,并且苦苦挣扎。
I have a snmpwalk command that works fine: 我有一个正常的snmpwalk命令:
$snmpwalk -v2c -c <our_community_string> <device_ip_address> 1.3.6.1.4.1.9.9.42.1.2.10.1.1.950
SNMPv2-SMI::enterprises.9.9.42.1.2.10.1.1.950 = Gauge32: 68
Now I'm trying to do the same thing in Python using pysnmp. 现在我正在尝试使用pysnmp在Python中做同样的事情。
I tried using something based on the examples here - http://pysnmp.sourceforge.net/examples/current/index.html - but got an SmiError: 我尝试使用基于这里的示例的东西 - http://pysnmp.sourceforge.net/examples/current/index.html - 但得到了一个SmiError:
In [1]: from pysnmp.entity.rfc3413.oneliner import cmdgen
In [2]: cmdGen = cmdgen.CommandGenerator()
In [3]: errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
...: cmdgen.CommunityData('0pe3aro'),
...: cmdgen.UdpTransportTarget(('10.65.113.28', 161)),
...: cmdgen.MibVariable('1.3.6.1.4.1.9.9.42.1.2.10.1.1.950', 0)
...: )
But I get the following: 但我得到以下内容:
SmiError: MIB file "1.3.6.1.4.1.9.9.42.1.2.10.1.1.950.py[co]" not found in search path
Basically - I wanted the equavilent of this in NetSNMP, but in PySNMP ( http://ben.akrin.com/?p=1234 ). 基本上 - 我想在NetSNMP中保持平衡,但在PySNMP( http://ben.akrin.com/?p=1234 )中。
Does anybody know a simple way to query a numerical OID in PySNMP? 有人知道在PySNMP中查询数字OID的简单方法吗?
Cheers, Victor 干杯,维克多
I believe the following code would work for you: 我相信以下代码适合您:
from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
'1.3.6.1.2.1.1.3.0'
)
print('\n'.join([ '%s = %s' % varBind for varBind in varBinds]))
You could cut&paste it into your Python prompt to try and experiment with it. 您可以将其剪切并粘贴到Python提示中以尝试进行实验。
The MibVariable object can be used for referring to a MIB symbol by name. MibVariable对象可用于按名称引用MIB符号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.