[pysnmp-users] Short Object ID
Brought to you by:
elie
|
From: Roland K. <kne...@gm...> - 2008-11-06 15:43:05
|
Hi,
I am new to Python and pysnmp and i am trying to send some SNMP-Get requests
to a system.
I'm using the 2.0.9 Release of PYSNMP and windows pc.
I modified the snmpget.py example to fit my requirements (I deleted all the
commandline stuff and set the port, oid stuff). That looks like that:
import sys
# Import PySNMP modules
from pysnmp import asn1, v1, v2c
from pysnmp import role
# Initialize defaults
port = 161
retries = 5
timeout = 1
version = 'v2c'
host = 'printsrv86'
oid='1.3.6.1.2.1.1.1'
community_string = 'public'
# Create SNMP manager object
client = role.manager((host,port))
# Pass it a few options
client.timeout = timeout
client.retries = retries
# Create a SNMP request&response objects from protocol version
# specific module.
try:
req = eval('v2c').GETREQUEST()
rsp = eval('v2c').GETRESPONSE()
except (NameError, AttributeError):
print 'Unsupported SNMP protocol version: %s\n%s' % (version, usage)
sys.exit(-1)
# Encode OIDs, encode SNMP request message and try to send
# it to SNMP agent and receive a response
(answer, src) = client.send_and_receive( \
req.encode(community=community_string, \
encoded_oids=map(asn1.OBJECTID().encode, oid[0:])))
# Decode SNMP response
rsp.decode(answer)
# Make sure response matches request (request IDs, communities, etc)
if req != rsp:
raise 'Unmatched response: %s vs %s' % (str(req), str(rsp))
# Decode BER encoded Object IDs.
oids = map(lambda x: x[0], map(asn1.OBJECTID().decode, \
rsp['encoded_oids']))
# Decode BER encoded values associated with Object IDs.
vals = map(lambda x: x[0](), map(asn1.decode, rsp['encoded_vals']))
# Check for remote SNMP agent failure
if rsp['error_status']:
raise 'SNMP error #' + str(rsp['error_status']) + ' for OID #' \
+ str(rsp['error_index'])
# Print out results
for (oid, val) in map(None, oids, vals):
print oid + ' ---> ' + str(val)
But when i run the script to send a snmp get request i get this:
Traceback (most recent call last):
File "C:\Python26\SkriptS\Collect.py", line 49, in <module>
encoded_oids=map(asn1.OBJECTID().encode, oid[0:])))
File "C:\Python26\lib\pysnmp\asn1.py", line 272, in encode
result = self._encode()
File "C:\Python26\lib\pysnmp\asn1.py", line 440, in _encode
raise BadArgument('Short Object ID: ' + str(oid))
BadArgument: Short Object ID: [1L]
The set oid is: '1.3.6.1.2.1.1.1'
I think that the script is somehow deleting a part of the given oid while
converting it in the asn1.py one line 567.
I hope sombody can help me.
|