Re: [pysnmp-users] PySNMP 4.3.1 strange prettyPrint() output
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2015-11-18 19:44:34
|
Hi Wei, I think you should not mess with .py MIBs at all. Once you have the pysmi package installed, pysnmp will pull text MIBs from whatever location you configure, compile them into .py and put the result in ~/.pysnmp/mibs/ (by default). To make pysnmp resolving OID-value pairs, the following requirements should be satisfied: 1) pysmi package installed (from pypi) 2) source (text) MIBs are available locally or via http, pysnmp is configured to search them there 3) you pre-load all MIBs you expect your agent to serve via ObjectType.loadMibs() call To figure out what is going on under the hood you can enable pysnmp debugging (the mibbuld component). The error you encounter occurs because your agent responded with a value (18) which is not present in the list of allowed values for that OID (2, 10, 1, 12, 5, 8, 3, 9, 7, 4, 6, 11). That is either a problem of the agent, or incorrect/outdated MIB or bug in text-to-pysnmp MIB compilation process. Where do you get your .py MIBs from? Advised way to obtain .py MIBs is either let pysmi/pysnmp do that automatically or you could use “mibdump” tool from pysmi package for manual MIB compilation. -ilya > On 18 Nov 2015, at 03:36, Wei Wang <ww...@9r...> wrote: > > Thanks, Ilya. > > I just did as you suggested, but that did not change the results. I had actually put the two MIBs (.py files) I built into .../dist-packages/pysnmp/smi/mibs/ folder, which is how I got the prettyPrint() to give me some MIB object names at all. Before I did that, none of the object IDs resolved to names. > > After that failed, I moved the line "snmp = SnmpEngine()" out of the walk_aptable() function into the global space. That actually made the code resolving all object names for prettyPrint(). > > However, I got a different error: > > 2015-11-17 21:17:53,195 ERROR base_events.default_exception_handler:1053 Exception in callback _cbFun(<pysnmp....94e5ad50>, ('10.50.0.13', 161), '0\x82\x05v\x... \x02\x01\x12') > handle: <Handle _cbFun(<pysnmp....94e5ad50>, ('10.50.0.13', 161), '0\x82\x05v\x... \x02\x01\x12')> > Traceback (most recent call last): > File "/usr/local/lib/python2.7/dist-packages/trollius/events.py", line 136, in _run > self._callback(*self._args) > File "/usr/local/lib/python2.7/dist-packages/pysnmp/carrier/base.py", line 63, in _cbFun > self, transportDomain, transportAddress, incomingMessage > File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/engine.py", line 140, in __receiveMessageCbFun > self, transportDomain, transportAddress, wholeMsg > File "/usr/local/lib/python2.7/dist-packages/pysnmp/proto/rfc3412.py", line 453, in receiveMessage > cachedParams['cbCtx']) > File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/cmdgen.py", line 125, in processResponsePdu > cbFun(snmpEngine, origSendRequestHandle, None, PDU, cbCtx) > File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/cmdgen.py", line 349, in processResponseVarBinds > varBindTable, cbCtx): > File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/asyncio/cmdgen.py", line 440, in __cbFun > (errorIndication, errorStatus, errorIndex, [vbProcessor.unmakeVarBinds(snmpEngine, varBindTableRow, lookupMib) for varBindTableRow in varBindTable]) > File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/varbinds.py", line 37, in unmakeVarBinds > varBinds = [ObjectType(ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController) for x in varBinds] > File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/rfc1902.py", line 728, in resolveWithMib > raise SmiError('Value %r to type %r convertion failure: %s' % (self.__args[1], self.__args[0].getMibNode().getSyntax().__class__.__name__, sys.exc_info()[1])) > SmiError: Value Integer(18) to type 'Integer32' convertion failure: ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueRangeConstraint(-2147483648, 2147483647)), SingleValueConstraint(2, 10, 1, 12, 5, 8, 3, 9, 7, 4, 6, 11)) failed at: "SingleValueConstraint(2, 10, 1, 12, 5, 8, 3, 9, 7, 4, 6, 11) failed at: "18"" at Integer32 > > Looks like that the code got a string value (18") which it attempted to convert to integer. I've been looking in the code a bit but was not able to figure out yet where that came from. > > -- Wei > > On Tue, Nov 17, 2015 at 7:25 PM, Ilya Etingof <il...@gl... <mailto:il...@gl...>> wrote: > Hi Wei, > > You need to pre-load MIBs that your agent implements and is likely to refer to in its responses. That can be done by adding ObjectType.loadMibs(‘YOUR-MIB1.txt’, ‘YOUR-MIB2.txt’) like this: > > http://pysnmp.sourceforge.net/examples/hlapi/asyncore/sync/manager/cmdgen/mib-tweaks.html#preload-pysnmp-mibs <http://pysnmp.sourceforge.net/examples/hlapi/asyncore/sync/manager/cmdgen/mib-tweaks.html#preload-pysnmp-mibs> > > -ilya > |