Re: [pysnmp-users] PySNMP 4.3.1 strange prettyPrint() output
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2015-11-18 00:25:30
|
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 > On 17 Nov 2015, at 22:38, Wei Wang <ww...@9r...> wrote: > > Hi, list, > > Thanks to the help from Ilya, I got my code to work with the latest pysnmp. > > But I am seeing some strange output from prettyPrint() with this function: > > @trollius.coroutine > def walk_aptable(wlc, cfg, varBinds): > snmp = SnmpEngine() > timeout = cfg['timeout'] > retries = cfg['retries'] > authData = CommunityData(cfg['community']) > transportTarget = cmdgen.UdpTransportTarget((wlc, 161), timeout=timeout, retries=retries) > logger.debug('walk_aptable: {0}'.format(wlc)) > while True: > errorIndication, errorStatus, errorIndex,\ > varBindTable = yield trollius.From( > cmdgen.bulkCmd( > snmp, > authData, > transportTarget, > ContextData(), > 0, 50, > *varBinds, > lookupNames=True, lookupValues=True > ) > ) > > if errorIndication: > logger.error('{0}: {1}'.format(transportTarget, errorIndication)) > break > if errorStatus: > logger.error( > '{0} at {1}'.format( > errorStatus.prettyPrint(), > errorIndex and varBindTable[-1][int(errorIndex)-1] or '?' > ) > ) > else: > for varBindRow in varBindTable: > for varBind in varBindRow: > logger.debug('{0}: {1}'.format( > transportTarget.getTransportInfo()[1][0], # IP address > ' = '.join([ x.prettyPrint() for x in varBind ]) > ) > ) > varBinds = varBindTable[-1] > if isEndOfMib(varBinds): > break > #snmp.transportDispatcher.closeDispatcher() > > That function is called like this: > > varbinds = [ ObjectType(ObjectIdentity('AIRESPACE-WIRELESS-MIB', 'bsnAPTable'))] > loop = trollius.get_event_loop() > loop.run_until_complete( > trollius.wait([walk_aptable(wlc, cfg, varbinds) for wlc in wlcs])) > > with 2 IP addresses in the "wlcs" list. > > The output is that the MIB object names from one device unresolved, like this: > > 2015-11-17 16:21:03,794 DEBUG ap.walk_aptable:199 10.50.0.12 <http://10.50.0.12/>: SNMPv2-SMI::enterprises.14179.2.2.1.1.1.0.20.27.88.56.240 = 0x00141b5838f0 > > with the same object names from another device resolved, like this: > > 2015-11-17 16:21:03,865 DEBUG ap.walk_aptable:199 10.50.0.13 <http://10.50.0.13/>: AIRESPACE-WIRELESS-MIB::bsnAPDot3MacAddress.00:08:30:00:76:10 = 00:08:30:00:76:10 > > What am I doing wrong? > > Thanks for any help! > -- > Wei Wang |