pysnmp-users Mailing List for SNMP library for Python (Page 6)
Brought to you by:
elie
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
(2) |
Sep
(3) |
Oct
(2) |
Nov
(4) |
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
(3) |
Mar
(16) |
Apr
(3) |
May
(6) |
Jun
|
Jul
(7) |
Aug
(12) |
Sep
(4) |
Oct
(2) |
Nov
(11) |
Dec
(6) |
2004 |
Jan
(1) |
Feb
(41) |
Mar
(4) |
Apr
(1) |
May
(6) |
Jun
|
Jul
(8) |
Aug
(5) |
Sep
(8) |
Oct
(10) |
Nov
(3) |
Dec
(1) |
2005 |
Jan
|
Feb
(4) |
Mar
(8) |
Apr
(4) |
May
(10) |
Jun
(5) |
Jul
(10) |
Aug
(6) |
Sep
(6) |
Oct
(39) |
Nov
(20) |
Dec
(21) |
2006 |
Jan
(14) |
Feb
(6) |
Mar
(15) |
Apr
|
May
(5) |
Jun
(16) |
Jul
(16) |
Aug
(18) |
Sep
(35) |
Oct
(12) |
Nov
(3) |
Dec
(3) |
2007 |
Jan
(12) |
Feb
(19) |
Mar
(27) |
Apr
(14) |
May
(32) |
Jun
|
Jul
(35) |
Aug
(11) |
Sep
(11) |
Oct
(6) |
Nov
(13) |
Dec
(4) |
2008 |
Jan
(7) |
Feb
(4) |
Mar
(2) |
Apr
(3) |
May
(3) |
Jun
(5) |
Jul
(5) |
Aug
(1) |
Sep
(2) |
Oct
(3) |
Nov
(19) |
Dec
(7) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
(12) |
Apr
(16) |
May
(16) |
Jun
(23) |
Jul
(7) |
Aug
(2) |
Sep
(17) |
Oct
(20) |
Nov
(20) |
Dec
(5) |
2010 |
Jan
(11) |
Feb
(17) |
Mar
(20) |
Apr
(7) |
May
(6) |
Jun
(14) |
Jul
(5) |
Aug
(10) |
Sep
(23) |
Oct
(16) |
Nov
(32) |
Dec
(21) |
2011 |
Jan
(6) |
Feb
(11) |
Mar
(3) |
Apr
(1) |
May
(4) |
Jun
(1) |
Jul
(4) |
Aug
(8) |
Sep
(20) |
Oct
(9) |
Nov
(29) |
Dec
(25) |
2012 |
Jan
(2) |
Feb
(5) |
Mar
(2) |
Apr
(22) |
May
(21) |
Jun
(7) |
Jul
(6) |
Aug
(2) |
Sep
(12) |
Oct
(20) |
Nov
(17) |
Dec
(17) |
2013 |
Jan
(4) |
Feb
(4) |
Mar
(8) |
Apr
(8) |
May
(10) |
Jun
(2) |
Jul
(23) |
Aug
(12) |
Sep
(14) |
Oct
(12) |
Nov
(4) |
Dec
(18) |
2014 |
Jan
(2) |
Feb
(7) |
Mar
(3) |
Apr
(8) |
May
(7) |
Jun
(1) |
Jul
(5) |
Aug
(2) |
Sep
(8) |
Oct
|
Nov
(2) |
Dec
(1) |
2015 |
Jan
(3) |
Feb
(15) |
Mar
(14) |
Apr
(4) |
May
(6) |
Jun
(3) |
Jul
(1) |
Aug
(6) |
Sep
(5) |
Oct
(21) |
Nov
(43) |
Dec
(10) |
2016 |
Jan
|
Feb
(2) |
Mar
(6) |
Apr
(4) |
May
(6) |
Jun
(2) |
Jul
(6) |
Aug
(5) |
Sep
(4) |
Oct
|
Nov
(3) |
Dec
(11) |
2017 |
Jan
(1) |
Feb
(8) |
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
(5) |
Aug
|
Sep
(9) |
Oct
(8) |
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
From: Ilya E. <il...@gl...> - 2015-11-18 20:11:37
|
Hi Michael, From the code snippet you sent, it’s hard to figure out what exactly is the problem. Also ‘thread’ module is somewhat low-level… I’ve run a quick test with pysnmp 4.3.1 and the 'threading’ module having three independent SNMP engines (managers) running in three threads plus one raw_input() loop in the other. So it seems to work alright (see attached). -ilya |
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 > |
From: Wei W. <ww...@9r...> - 2015-11-18 02:37:02
|
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...> 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 > > -ilya > > |
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 |
From: Wei W. <ww...@9r...> - 2015-11-17 21:39:05
|
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: 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: 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 |
From: Wei W. <ww...@9r...> - 2015-11-17 14:17:58
|
Okay. Just did a "pip install --upgrade pyasn1", then "pip install --upgrade pysnmp" back to 4.3.1. Got the exact same error messages. On Tue, Nov 17, 2015 at 9:13 AM, Ilya Etingof <il...@gl...> wrote: > Please, also upgrade your pyasn1 package to the latest pip version. > |
From: Ilya E. <il...@gl...> - 2015-11-17 14:13:34
|
Please, also upgrade your pyasn1 package to the latest pip version. > On 17 Nov 2015, at 15:11, Wei Wang <ww...@9r...> wrote: > > Just did. No luck - See messages below - This test code works with PySNMP 4.2.2 and 4.2.5. <http://4.2.5./>: > > Exception raised: > Traceback (most recent call last): > > File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 588, in setValue > File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-TC.py", line 284, in setValue > AttributeError: RowStatus instance has no attribute 'hasValue' > ********************************************************************** > > On Fri, Nov 13, 2015 at 3:30 PM, Ilya Etingof <il...@gl... <mailto:il...@gl...>> wrote: > Please try the latest version available through pip (4.3.1) > > |
From: Wei W. <ww...@9r...> - 2015-11-17 14:12:00
|
Just did. No luck - See messages below - This test code works with PySNMP 4.2.2 and 4.2.5.: Exception raised: Traceback (most recent call last): File "/usr/lib/python2.7/doctest.py", line 1315, in __run compileflags, 1) in test.globs File "<doctest ap.test[4]>", line 1, in <module> app(hostlist) File "/home/weiwang/oss/netopy/inventory/ap.py", line 124, in __call__ (cbFun, (varBindHead, transportTarget)) #, lookupNames=True, lookupValues=True File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 124, in nextCmd lookupMib=lookupNames or lookupValues) File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 333, in nextCmd addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget) File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/lcd.py", line 38, in configure authData.securityName File "/usr/local/lib/python2.7/dist-packages/pysnmp/entity/config.py", line 67, in addV1System ((snmpCommunityEntry.name + (8,) + tblIdx, 'destroy'),) File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 245, in writeVars return self.flipFlopFsm(self.fsmWriteVar, vars, acInfo) File "/usr/local/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 213, in flipFlopFsm rval = f(tuple(name), val, idx, acInfo) File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 467, in writeTest File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1102, in writeTest File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 1078, in __delegate File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 879, in writeTest File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 790, in createTest File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 696, in createTest File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-SMI.py", line 588, in setValue File "/tmp/pip_build_root/pysnmp/pysnmp/smi/mibs/SNMPv2-TC.py", line 284, in setValue AttributeError: RowStatus instance has no attribute 'hasValue' ********************************************************************** On Fri, Nov 13, 2015 at 3:30 PM, Ilya Etingof <il...@gl...> wrote: > Please try the latest version available through pip (4.3.1) > > |
From: Ilya E. <il...@gl...> - 2015-11-16 18:29:14
|
Hi Michael, SNMP does not touch stdin but blocks on waiting for UDP socket to receive response packet from remove server. In the same time cly blocks waiting on stdin's file descriptor (FD) for your input (yes, raw_input() is blocking by default). Whenever you have a single thread of execution in your program and two blocking calls, you have to execute one or the other at a time. Unless you 1) put one of these calls to a parallel thread of execution or 2) make both blocking calls cooperating thus letting the other one to run while its fellow would block. The first approach is known as a multi-threading design, while the latter is called asynchronous I/O. In your case MT might be easier to implement, so I’d try it first. In fact I had an impression that you already did that by putting SNMP part into a dedicated thread (via the threading module). Async requires more effort and mind wrapping. The idea is that you switch potentially blocking FDs (sockets) into a non-blocking mode, then pass a collection of them to a dispatcher (select(), poll() etc.) that will watch them for readiness. Once one FD/socket is ready, you could pass it to read()/recvfrom() calls to perform actual I/O. No blocking is done if you do read from FD that has nothing to return - it will indicate that with an error immediately. The only waiting entity with this design is the dispatcher. I’ve come across many discussion on the topic: https://repolinux.wordpress.com/2012/10/09/non-blocking-read-from-stdin-in-python/ Hope this helps, Ilya > On 15 Nov 2015, at 04:31, Michael R Anderson <mic...@gm...> wrote: > > Hi Ilya, > I didn't mean to say the pysnmp thread blocks the cly thread or vice > versa. Just that executing rundispather() stopped the command line > input from reaching cly. That's all I meant. > > Is the problem raw_input blocking I/O? Or is it that only one of cly > or pysnmp reads all input (stdin and port 161), keeps what the map > says to recognize, ignores the rest, and starves the other of it's > input? Or did I misunderstand? If that is correct, then if I combine > the input map from cly with that for pysnmp, either using cly to drive > or snmp to drive, then somehow I have to get the input (from > stdin/port 161) from whichever read it to the other. > > Is that about right? Any better alternative. > > Thanks, > -Mike > > On Sat, Nov 14, 2015 at 12:14 PM, Ilya Etingof <il...@gl...> wrote: >> >> The first thing I do not quite understand is why your SNMP call blocks >> (?) your cly app if your (blocking) pysnmp code runs in a dedicated >> thread. Can you please elaborate on that point? >> >> Alternatively, as Craig says, you may try to switch your stdin file >> descriptor into non-blocking mode and serve both FD's (SNMP and stdin) >> by a single select() within a main loop. >> >> To start with the second approach, I'd investigate the way how to extent >> ply input driver to run non-blocking and being managed by a select(). >> I've looked at the ply code: >> >> https://github.com/alecthomas/cly/blob/master/cly/interactive.py >> >> so ReadlineDriver class is the place that should probably be >> hacked/extended to replace blocking raw_inpit() with a non-blocking and >> select()-managed version like discussed here: >> >> http://stackoverflow.com/questions/9027311/how-to-make-non-blocking-raw-input-when-using-eventlet-monkey-patch-and-why-it >> >> Once this is working, I could elaborate on >> two-FDs-been-managed-by-single-select thing. I will probably try to come >> up with an example script to make it generally useful. >> >> -ilya >> >> On 11/12/2015 11:15 AM, Craig Small wrote: >>> Avtually re-reading your email, its not two sockets its an interactive >>> terminal and a socket. What you can do is put your stdin socket (well >>> FD) into the socket map. That way the select() is looking at both your >>> network SNMP socket/fd and your keyboard stdin >>> >>> - Craig >>> >>> >>> On Thu, Nov 12, 2015 at 9:09 PM Craig Small <cs...@en... >>> <mailto:cs...@en...>> wrote: >>> >>> >>> Get's a bit tricky with sockets floating around. What I had to do >>> was create a new SNMP engine and dispatcher that used my own >>> socket_map. The socket_map is important because this is what the >>> select() system calls to listen for the sockets. You can have only >>> one select() >>> >>> You then need to run the dispatcher's jobsArePending and >>> handleTimerTick to keep the the snmp dispatcher happy. >>> >>> I then have the the socket running select(), because you have used >>> YOUR socket_map then pysnmp has added its socket to the map. >>> I asked almost the very same thing and Ilya responded here: >>> >>> http://sourceforge.net/p/pysnmp/mailman/message/31494830/ >>> >>> >>> >>> On Thu, Nov 12, 2015 at 11:57 AM Michael R Anderson >>> <mic...@gm... <mailto:mic...@gm...>> >>> wrote: >>> >>> I am using cly to drive my CLI. It works great. I recently added >>> pysmp. Now when it gets to runDispatcher() (in it's own thread), it >>> looks like my CLI input line gets hijacked so that no more command >>> line input can be done. >>> >>> I read runDispacther uses an I/O mainloop somehow. Can this be >>> causing my CLI is no responsive problem? >>> >>> Any suggestions? >>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> pysnmp-users mailing list >>> pys...@li... >>> <mailto:pys...@li...> >>> https://lists.sourceforge.net/lists/listinfo/pysnmp-users >>> >>> -- >>> Craig Small (@smallsees) http://enc.com.au/ csmall at : >>> enc.com.au <http://enc.com.au> >>> Debian GNU/Linux http://www.debian.org/ csmall at : >>> debian.org <http://debian.org> >>> GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B >>> DF50 FEA5 >>> >>> -- >>> Craig Small (@smallsees) http://enc.com.au/ csmall at : >>> enc.com.au <http://enc.com.au> >>> Debian GNU/Linux http://www.debian.org/ csmall at : >>> debian.org <http://debian.org> >>> GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5 >>> >>> >>> ------------------------------------------------------------------------------ >>> >>> >>> >>> _______________________________________________ >>> pysnmp-users mailing list >>> pys...@li... >>> https://lists.sourceforge.net/lists/listinfo/pysnmp-users >>> |
From: Vincent B. <be...@lu...> - 2015-11-15 22:02:39
|
❦ 15 novembre 2015 17:30 +0100, Vincent Bernat <be...@lu...> : > Since many stuff doesn't seem to be thread safe and that SnmpEngine is > only parsing MIB stuff to get constant data, this part should be > extracted to do it once. All the more than starting with PySNMP 4.3, MIBs are parsed/compiled with PySMI. I can't say for sure, but is it safe to compile a MIB from different threads? It seems that ply is not thread-safe. It is said: ╭─────┤ https://github.com/dabeaz/ply/blob/master/ply/yacc.py#L40-L45 ├───── │The current implementation is only somewhat object-oriented. The │LR parser itself is defined in terms of an object (which allows multiple │parsers to co-exist). However, most of the variables used during table │construction are defined in terms of global variables. Users shouldn't │notice unless they are trying to define multiple parsers at the same │time using threads (in which case they should have their head │examined). ╰───── -- You may my glories and my state dispose, But not my griefs; still am I king of those. -- William Shakespeare, "Richard II" |
From: Vincent B. <be...@lu...> - 2015-11-15 16:47:43
|
❦ 1 juillet 2015 00:46 +0200, Ilya Etingof <il...@gl...> : > In the latest (almost released) pysnmp AsyncCommandGenerator API > reworked to become stateless. It is AsyncCommandGenerator class that > does most of work. CommandGenerator is a thin wrapper creating and > hiding SnmpEngine instance aimed at simple use cases. > > All state (a lot of it) is bound to snmpEngine object. Any > AsyncCommandGenerator call must be done with snmpEngine object > reference. > > Here’s example code: > > http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/examples/v3arch/oneliner/manager/cmdgen/get-async-multiple-snmp-engines.py?view=markup > > I’d be very interested knowing if that new API works for you before > it’s too late (pysnmp is released). ;-) So, I had a look at PySNMP 4.3 but it seems that CommandGenerator is no longer using AsynCommandGenerator. I can provide my own SnmpEngine but SnmpEngine is still not thread-safe. A quick summary: I am trying to use multiple threads with several managers per thread (but a given manager is created and lives in a single thread). I am also trying to avoid the costly creation of a CommandGenerator (which parses MIB). What does not work: 1. Having CommandGenerator as a singleton and using a single thread. This fails when spawning commands from the same command generator with different USM. This should not and using the structure of usmUserTable (which is for a single agent) to store stuff for a manager talking to multiple agents is a bad idea. The cache should not just be a usmUserTable. It should also be indexed by other security parameters or by the target agent (but we don't know it yet when creating this structure). 2. Having CommandGenerator as a singleton and using multiple threads with SNMPv1/v2 managers. This fails because SnmpEngine is not thread-safe. 3. Having SnmpEngine as a singleton and using multiple threads with SNMPv1/v2 managers, each manager having its own CommandGenerator using the global SnmpEngine. SnmpEngine is not thread-safe and this doesn't work either. 4. Gaving CommandGenerator as a thread-local storage singleton. This fails again with SNMPv3 when the same threads has several managers (talking to several agents). What works: 1. Having one CommandGenerator for each manager. Works fine. Slow as hell when you need to spawn them fast. 2. Having CommandGenerator as a thread-local storage singleton with SNMPv1/v2 managers. Works fine. However, spawning multiple threads is slow as hell. Since many stuff doesn't seem to be thread safe and that SnmpEngine is only parsing MIB stuff to get constant data, this part should be extracted to do it once. The other idea would be to stuff the context of a new SnmpEngine with the mibViewController of a previous SnmpEngine. Thoughts? -- Test programs at their boundary values. - The Elements of Programming Style (Kernighan & Plauger) |
From: Ilya E. <il...@gl...> - 2015-11-14 18:14:56
|
The first thing I do not quite understand is why your SNMP call blocks (?) your cly app if your (blocking) pysnmp code runs in a dedicated thread. Can you please elaborate on that point? Alternatively, as Craig says, you may try to switch your stdin file descriptor into non-blocking mode and serve both FD's (SNMP and stdin) by a single select() within a main loop. To start with the second approach, I'd investigate the way how to extent ply input driver to run non-blocking and being managed by a select(). I've looked at the ply code: https://github.com/alecthomas/cly/blob/master/cly/interactive.py so ReadlineDriver class is the place that should probably be hacked/extended to replace blocking raw_inpit() with a non-blocking and select()-managed version like discussed here: http://stackoverflow.com/questions/9027311/how-to-make-non-blocking-raw-input-when-using-eventlet-monkey-patch-and-why-it Once this is working, I could elaborate on two-FDs-been-managed-by-single-select thing. I will probably try to come up with an example script to make it generally useful. -ilya On 11/12/2015 11:15 AM, Craig Small wrote: > Avtually re-reading your email, its not two sockets its an interactive > terminal and a socket. What you can do is put your stdin socket (well > FD) into the socket map. That way the select() is looking at both your > network SNMP socket/fd and your keyboard stdin > > - Craig > > > On Thu, Nov 12, 2015 at 9:09 PM Craig Small <cs...@en... > <mailto:cs...@en...>> wrote: > > > Get's a bit tricky with sockets floating around. What I had to do > was create a new SNMP engine and dispatcher that used my own > socket_map. The socket_map is important because this is what the > select() system calls to listen for the sockets. You can have only > one select() > > You then need to run the dispatcher's jobsArePending and > handleTimerTick to keep the the snmp dispatcher happy. > > I then have the the socket running select(), because you have used > YOUR socket_map then pysnmp has added its socket to the map. > I asked almost the very same thing and Ilya responded here: > > http://sourceforge.net/p/pysnmp/mailman/message/31494830/ > > > > On Thu, Nov 12, 2015 at 11:57 AM Michael R Anderson > <mic...@gm... <mailto:mic...@gm...>> > wrote: > > I am using cly to drive my CLI. It works great. I recently added > pysmp. Now when it gets to runDispatcher() (in it's own thread), it > looks like my CLI input line gets hijacked so that no more command > line input can be done. > > I read runDispacther uses an I/O mainloop somehow. Can this be > causing my CLI is no responsive problem? > > Any suggestions? > > ------------------------------------------------------------------------------ > _______________________________________________ > pysnmp-users mailing list > pys...@li... > <mailto:pys...@li...> > https://lists.sourceforge.net/lists/listinfo/pysnmp-users > > -- > Craig Small (@smallsees) http://enc.com.au/ csmall at : > enc.com.au <http://enc.com.au> > Debian GNU/Linux http://www.debian.org/ csmall at : > debian.org <http://debian.org> > GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B > DF50 FEA5 > > -- > Craig Small (@smallsees) http://enc.com.au/ csmall at : > enc.com.au <http://enc.com.au> > Debian GNU/Linux http://www.debian.org/ csmall at : > debian.org <http://debian.org> > GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5 > > > ------------------------------------------------------------------------------ > > > > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users > |
From: Craig S. <cs...@en...> - 2015-11-14 00:42:15
|
On Wed, Nov 11, 2015 at 06:56:36PM -0600, Michael R Anderson wrote: > I am using cly to drive my CLI. It works great. I recently added > pysmp. Now when it gets to runDispatcher() (in it's own thread), it > looks like my CLI input line gets hijacked so that no more command > line input can be done. I actually have written some test code showing a simple stdin reader working with pysnmp. It happily loops around servicing the snmp sockets and the stdin socket. Even uses the nice new hlapi (nice work Ilya). I thought, ok good, you get the data from stdin and feed it into cly and the world is good. but... cly uses raw_input[1] and that blocks :( So you have options: 1) re-write a cly InputDriver that doesn't use raw_input() but something a little less block-happy 2) Use threads, one for the input, one for SNMP and somehow get them to talk to each other (but you might have a raw_input blocks on my IPC socket problem anyhow) 3) Use a simple stdin input and somehow wedge the input characters into cly's parser. 4) Depending on the design of the app, either have cly running or SNMP running but not both. The last option would mean using your own Interact class and running every until some flag changed, the interact would need to make that check function below return true when it wants snmp to run. while True: while doInput: myInteract.once() if checkWeShouldDoSomeSnmpNow(): doInput = False else: # Now we sit here doing SNMP transportDispatcher.runDispatcher() doInput = True or something like that. - Craig [1] https://github.com/alecthomas/cly/blob/master/cly/interactive.py#L131 -- Craig Small (@smallsees) http://enc.com.au/ csmall at : enc.com.au Debian GNU/Linux http://www.debian.org/ csmall at : debian.org GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5 |
From: Ilya E. <il...@gl...> - 2015-11-13 20:36:32
|
Hi Patrick, I’ve finally pushed pysnmp 4.3.1 to PyPI. Please, re-test and let me know if any issues remain unaddressed. Another change is a high-level py/SNMP tutorial that is shipped with pysnmp sources and is also available online: http://pysnmp.sourceforge.net/docs/tutorial.html > On 28 okt. 2015, at 22:25, Ilya Etingof <il...@gl... <mailto:il...@gl...>> wrote: > >> I’m looking to push it up there by the coming weekend, but not quite sure I get enough time for regression. I’ll send a note to this list as it’s done. >> >>> On 28 Oct 2015, at 22:19, Patrick Ogenstad <pa...@og... <mailto:pa...@og...>> wrote: >>> >>> Thanks! >>> >>> Do you have any estimate as to when 4.3.1 will be on pypi and able to be installed by pip? >>> >>> On 28 okt. 2015, at 21:37, Ilya Etingof <il...@gl... <mailto:il...@gl...>> wrote: >>> >>>> Hi Patrick, >>>> >>>> That issue has been fixed in 4.3.1. Please try it out and let me know in case of further issues: >>>> >>>> tarball download <http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar> >>>>> On 28 Oct 2015, at 20:34, Patrick Ogenstad <pa...@og... <mailto:pa...@og...>> wrote: >>>>> >>>>> Hello, >>>>> >>>>> I ran into a problem after upgrading to pysnmp 4.3.0. >>>>> >>>>> Just running snmpwalk it looks like this: >>>>> >>>>> $ snmpwalk -v2c -c public 172.29.50.5 1.3.6.1.4.1.9.9.46.1.4.2 >>>>> SNMPv2-SMI::enterprises.9.9.46.1.4.2 = No Such Object available on this agent at this OID >>>>> >>>>> The problem seems to be when you run a nextCmd against an object which currently doesn't exist. >>>>> >>>>> The code below works with pysnmp 4.2.5 >>>>> >>>>> from pysnmp.entity.rfc3413.oneliner import cmdgen >>>>> cmdGen = cmdgen.CommandGenerator() >>>>> >>>>> errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd( >>>>> cmdgen.CommunityData('public'), >>>>> cmdgen.UdpTransportTarget(('172.29.50.5', 161)), >>>>> '1.3.6.1.4.1.9.9.46.1.4.2', >>>>> lookupMib=False, >>>>> ) >>>>> >>>>> if errorIndication: >>>>> print(errorIndication) >>>>> else: >>>>> if errorStatus: >>>>> print('%s at %s' % ( >>>>> errorStatus.prettyPrint(), >>>>> errorIndex and varBindTable[-1][int(errorIndex)-1] or '?' >>>>> ) >>>>> ) >>>>> else: >>>>> for varBindTableRow in varBindTable: >>>>> for name, val in varBindTableRow: >>>>> print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) >>>>> >>>>> As the object doesn't exist on the device nothing is printed out. However running the same code with 4.3.0 gives this error: >>>>> >>>>> Traceback (most recent call last): >>>>> File "<stdin>", line 5, in <module> >>>>> File "/Users/patrick/.virtualenvs/prod/lib/python2.7/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 222, in nextCmd >>>>> return errorIndication, errorStatus, errorIndex, varBindTable >>>>> UnboundLocalError: local variable 'errorIndication' referenced before assignment >>>>> >>>>> Is this something which can be solved in an easy way? >>>>> >>>>> Best regards >>>>> Patrick >> |
From: Ilya E. <il...@gl...> - 2015-11-13 20:30:18
|
Please try the latest version available through pip (4.3.1) > On 12 Nov 2015, at 22:08, Wei Wang <ww...@9r...> wrote: > > Greetings, > > With pysnmp v4.3.0 installed using "pip", I get an "AttributeError" running the example code getbulk-to-eom1.py. > > Looked into the source code a bit and found only the two lines below in pysnmp/smi/mibs/SNMPv2-TC.py: > > $ find . -name \*.py -exec grep -wn hasValue {} /dev/null \; > ./pysnmp/smi/mibs/SNMPv2-TC.py:284: (value.hasValue() and value or self.stNotExists, > ./pysnmp/smi/mibs/SNMPv2-TC.py:285: self.hasValue() and self or self.stNotExists), > > Has anyone else seen this issue? > > Thanks. > -- > Wei Wang |
From: Ilya E. <il...@gl...> - 2015-11-12 21:50:38
|
Hi Wei, Please try the next version: http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar > On 12 Nov 2015, at 22:08, Wei Wang <ww...@9r...> wrote: > > Greetings, > > With pysnmp v4.3.0 installed using "pip", I get an "AttributeError" running the example code getbulk-to-eom1.py. > > Looked into the source code a bit and found only the two lines below in pysnmp/smi/mibs/SNMPv2-TC.py: > > $ find . -name \*.py -exec grep -wn hasValue {} /dev/null \; > ./pysnmp/smi/mibs/SNMPv2-TC.py:284: (value.hasValue() and value or self.stNotExists, > ./pysnmp/smi/mibs/SNMPv2-TC.py:285: self.hasValue() and self or self.stNotExists), > > Has anyone else seen this issue? > > Thanks. > -- > Wei Wang > ------------------------------------------------------------------------------ > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Wei W. <ww...@9r...> - 2015-11-12 21:34:46
|
Greetings, With pysnmp v4.3.0 installed using "pip", I get an "AttributeError" running the example code getbulk-to-eom1.py. Looked into the source code a bit and found only the two lines below in pysnmp/smi/mibs/SNMPv2-TC.py: $ find . -name \*.py -exec grep -wn hasValue {} /dev/null \; ./pysnmp/smi/mibs/SNMPv2-TC.py:284: (value.hasValue() and value or self.stNotExists, ./pysnmp/smi/mibs/SNMPv2-TC.py:285: self.hasValue() and self or self.stNotExists), Has anyone else seen this issue? Thanks. -- Wei Wang |
From: Craig S. <cs...@en...> - 2015-11-12 10:33:25
|
Get's a bit tricky with sockets floating around. What I had to do was create a new SNMP engine and dispatcher that used my own socket_map. The socket_map is important because this is what the select() system calls to listen for the sockets. You can have only one select() You then need to run the dispatcher's jobsArePending and handleTimerTick to keep the the snmp dispatcher happy. I then have the the socket running select(), because you have used YOUR socket_map then pysnmp has added its socket to the map. I asked almost the very same thing and Ilya responded here: http://sourceforge.net/p/pysnmp/mailman/message/31494830/ On Thu, Nov 12, 2015 at 11:57 AM Michael R Anderson < mic...@gm...> wrote: > I am using cly to drive my CLI. It works great. I recently added > pysmp. Now when it gets to runDispatcher() (in it's own thread), it > looks like my CLI input line gets hijacked so that no more command > line input can be done. > > I read runDispacther uses an I/O mainloop somehow. Can this be > causing my CLI is no responsive problem? > > Any suggestions? > > > ------------------------------------------------------------------------------ > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users > -- Craig Small (@smallsees) http://enc.com.au/ csmall at : enc.com.au Debian GNU/Linux http://www.debian.org/ csmall at : debian.org GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5 |
From: Craig S. <cs...@en...> - 2015-11-12 10:23:07
|
Avtually re-reading your email, its not two sockets its an interactive terminal and a socket. What you can do is put your stdin socket (well FD) into the socket map. That way the select() is looking at both your network SNMP socket/fd and your keyboard stdin - Craig On Thu, Nov 12, 2015 at 9:09 PM Craig Small <cs...@en...> wrote: > > Get's a bit tricky with sockets floating around. What I had to do was > create a new SNMP engine and dispatcher that used my own socket_map. The > socket_map is important because this is what the select() system calls to > listen for the sockets. You can have only one select() > > You then need to run the dispatcher's jobsArePending and handleTimerTick > to keep the the snmp dispatcher happy. > > I then have the the socket running select(), because you have used YOUR > socket_map then pysnmp has added its socket to the map. > I asked almost the very same thing and Ilya responded here: > > http://sourceforge.net/p/pysnmp/mailman/message/31494830/ > > > > On Thu, Nov 12, 2015 at 11:57 AM Michael R Anderson < > mic...@gm...> wrote: > >> I am using cly to drive my CLI. It works great. I recently added >> pysmp. Now when it gets to runDispatcher() (in it's own thread), it >> looks like my CLI input line gets hijacked so that no more command >> line input can be done. >> >> I read runDispacther uses an I/O mainloop somehow. Can this be >> causing my CLI is no responsive problem? >> >> Any suggestions? >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> pysnmp-users mailing list >> pys...@li... >> https://lists.sourceforge.net/lists/listinfo/pysnmp-users >> > -- > Craig Small (@smallsees) http://enc.com.au/ csmall at : enc.com.au > Debian GNU/Linux http://www.debian.org/ csmall at : debian.org > GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5 > -- Craig Small (@smallsees) http://enc.com.au/ csmall at : enc.com.au Debian GNU/Linux http://www.debian.org/ csmall at : debian.org GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5 |
From: Michael R A. <mic...@gm...> - 2015-11-12 00:56:43
|
I am using cly to drive my CLI. It works great. I recently added pysmp. Now when it gets to runDispatcher() (in it's own thread), it looks like my CLI input line gets hijacked so that no more command line input can be done. I read runDispacther uses an I/O mainloop somehow. Can this be causing my CLI is no responsive problem? Any suggestions? |
From: Ilya E. <il...@gl...> - 2015-11-10 07:23:34
|
Hi Diego, OctetString can also take a sequence of bytes: >>> OctetString([1, 32, 73, 0xf0, 0xff]) OctetString(hexValue='012049f0ff') >>> str(OctetString([1, 32, 73, 0xf0, 0xff])) '\x01 I\xf0\xff’ -ilya > On 07 Nov 2015, at 18:59, Diego Muñoz <dmu...@gm...> wrote: > > Sadly I won't be able to work with the device until monday or tuesday maybe. As soon as I can, I will send another email. > > Meanwhile, I want to ask an extra question. > I have to create the OctetString based on 6 different values. What I currently do is to create a hex string with the corresponding byte length for each value, then use the binascii.unhexlify function and finally create the OctetString with this result: > > message = duration_hex + activatePriority_hex + messageMemoryType_hex + \ > messageNumber_hex + messageCRC_hex + deviceIp_hex > message = binascii.unhexlify(message) > > An example of the hex string is: > "ff ff ff 03 00 3c 2f f5 c0 a8 01 de" (blank spaces added to read easily) > where: > duration_hex = ff ff > activatePriority_hex = ff > messageMemoryType_hex = 03 > messageNumber_hex = 00 3c > messageCRC_hex = 2f f5 > deviceIp_hex = c0 a8 01 de > > Is there a cleaner way to create the OctetString? > > 2015-11-06 20:14 GMT-03:00 Ilya Etingof <il...@gl...>: > Hi Diego, > > Try to enable pysnmp debug and see what OID and what value type (is it still OctetString?) is being sent in the second case: > > from pysnmp import debug > > debug.setDebug(debug.Debug(‘msgproc’)) > > -ilya > > >> On 06 Nov 2015, at 22:21, Diego Muñoz <dmu...@gm...> wrote: >> >> Hi Ilya, I am using the correct community, and I could successfully change the image with this code: >> >> from pysnmp.entity.rfc3413.oneliner import cmdgen >> from pysnmp.proto.rfc1902 import OctetString >> >> device_ip = '192.168.1.222' >> port = 6000 >> >> cmdGen = cmdgen.CommandGenerator() >> >> a = '\xff\xff\xff\x03\x00\x3c\x2f\xf5\x00\x00\x00\x00' >> >> errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( >> cmdgen.CommunityData('public'), >> cmdgen.UdpTransportTarget((device_ip, port)), >> ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), >> lookupNames=True, lookupValues=True >> ) >> >> I could finally understand the bytes in the sequence and get the OID of the object and the Octet String argument that I have to provide. This octet string (variable "a" in the code I wrote) contains 6 parameters, including the type of memory (03) and the memory number that corresponds to the image (00 3c). >> >> Now, what I don't get is why the new code works, when the only difference is the way I refer to the function I call: >> >> Code that does not work: >> (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), >> OctetString(a)), >> >> Code that works: >> ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), >> >> >> 2015-11-06 17:29 GMT-03:00 Ilya Etingof <il...@gl...>: >> >> Hi Diego, >> >> Make sure you are using correct community name, for SET queries it is frequently defaulted to ‘private’. >> >> If you show me the byte-string that works, I can possibly come up with corresponding SNMP message. >> >> -ilya >> >> > On 05 Nov 2015, at 17:02, Diego Muñoz <dmu...@gm...> wrote: >> > >> > Hello everyone, >> > >> > I have been working with NTCIP for only one week, and I need to change an image on a device by sending a SNMP activation message. I have been given the corresponding MIB, and a byte sequence of a SNMP message. >> > >> > I recently understood how the sequence is formed, and its components. I identified the MIB OID to activate the image, and identified the parameters that I need to give to the function. By editing the byte sequence, I can successfully send the message and change the image with python sockets using UDP. I also can successfully get information from the device with PySNMP and the getCmd function. >> > >> > The problem I have is that I try to setCmd the message and I only get a Timeout from the device. This is the code of my setCmd >> > >> > from pysnmp.entity.rfc3413.oneliner import cmdgen >> > from pysnmp.proto.rfc1902 import OctetString >> > >> > device_ip = '192.168.1.222' >> > port = 6000 >> > >> > cmdGen = cmdgen.CommandGenerator() >> > >> > # this variable includes the parameters I need to send to the device >> > a = '\xff\xff\xff\x03\x00\x0a\x2f\xf5\x00\x00\x00\x00' >> > >> > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( >> > cmdgen.CommunityData('public'), >> > cmdgen.UdpTransportTarget((device_ip, port)), >> > (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), >> > OctetString(a)), >> > lookupNames=True, lookupValues=True >> > ) >> > >> > I don't know which part is wrong, I would appreciate any help. >> > Regards, >> > Diego >> >> >> > > > ------------------------------------------------------------------------------ > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Diego M. <dmu...@gm...> - 2015-11-07 18:00:07
|
Sadly I won't be able to work with the device until monday or tuesday maybe. As soon as I can, I will send another email. Meanwhile, I want to ask an extra question. I have to create the OctetString based on 6 different values. What I currently do is to create a hex string with the corresponding byte length for each value, then use the binascii.unhexlify function and finally create the OctetString with this result: message = duration_hex + activatePriority_hex + messageMemoryType_hex + \ messageNumber_hex + messageCRC_hex + deviceIp_hex message = binascii.unhexlify(message) An example of the hex string is: "ff ff ff 03 00 3c 2f f5 c0 a8 01 de" (blank spaces added to read easily) where: duration_hex = ff ff activatePriority_hex = ff messageMemoryType_hex = 03 messageNumber_hex = 00 3c messageCRC_hex = 2f f5 deviceIp_hex = c0 a8 01 de Is there a cleaner way to create the OctetString? 2015-11-06 20:14 GMT-03:00 Ilya Etingof <il...@gl...>: > Hi Diego, > > Try to enable pysnmp debug and see what OID and what value type (is it > still OctetString?) is being sent in the second case: > > from pysnmp import debug > > debug.setDebug(debug.Debug(‘msgproc’)) > > -ilya > > > On 06 Nov 2015, at 22:21, Diego Muñoz <dmu...@gm...> wrote: > > Hi Ilya, I am using the correct community, and I could successfully change > the image with this code: > > from pysnmp.entity.rfc3413.oneliner import cmdgen > from pysnmp.proto.rfc1902 import OctetString > > device_ip = '192.168.1.222' > port = 6000 > > cmdGen = cmdgen.CommandGenerator() > > a = '\xff\xff\xff\x03\x00\x3c\x2f\xf5\x00\x00\x00\x00' > > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( > cmdgen.CommunityData('public'), > cmdgen.UdpTransportTarget((device_ip, port)), > ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), > lookupNames=True, lookupValues=True > ) > > I could finally understand the bytes in the sequence and get the OID of > the object and the Octet String argument that I have to provide. This octet > string (variable "a" in the code I wrote) contains 6 parameters, including > the type of memory (03) and the memory number that corresponds to the image > (00 3c). > > Now, what I don't get is why the new code works, when the only difference > is the way I refer to the function I call: > > Code that does not work: > (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), > OctetString(a)), > > Code that works: > ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), > > > 2015-11-06 17:29 GMT-03:00 Ilya Etingof <il...@gl...>: > >> >> Hi Diego, >> >> Make sure you are using correct community name, for SET queries it is >> frequently defaulted to ‘private’. >> >> If you show me the byte-string that works, I can possibly come up with >> corresponding SNMP message. >> >> -ilya >> >> > On 05 Nov 2015, at 17:02, Diego Muñoz <dmu...@gm...> wrote: >> > >> > Hello everyone, >> > >> > I have been working with NTCIP for only one week, and I need to change >> an image on a device by sending a SNMP activation message. I have been >> given the corresponding MIB, and a byte sequence of a SNMP message. >> > >> > I recently understood how the sequence is formed, and its components. I >> identified the MIB OID to activate the image, and identified the parameters >> that I need to give to the function. By editing the byte sequence, I can >> successfully send the message and change the image with python sockets >> using UDP. I also can successfully get information from the device with >> PySNMP and the getCmd function. >> > >> > The problem I have is that I try to setCmd the message and I only get a >> Timeout from the device. This is the code of my setCmd >> > >> > from pysnmp.entity.rfc3413.oneliner import cmdgen >> > from pysnmp.proto.rfc1902 import OctetString >> > >> > device_ip = '192.168.1.222' >> > port = 6000 >> > >> > cmdGen = cmdgen.CommandGenerator() >> > >> > # this variable includes the parameters I need to send to the device >> > a = '\xff\xff\xff\x03\x00\x0a\x2f\xf5\x00\x00\x00\x00' >> > >> > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( >> > cmdgen.CommunityData('public'), >> > cmdgen.UdpTransportTarget((device_ip, port)), >> > (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), >> > OctetString(a)), >> > lookupNames=True, lookupValues=True >> > ) >> > >> > I don't know which part is wrong, I would appreciate any help. >> > Regards, >> > Diego >> >> >> > > |
From: Ilya E. <il...@gl...> - 2015-11-06 23:14:21
|
Hi Diego, Try to enable pysnmp debug and see what OID and what value type (is it still OctetString?) is being sent in the second case: from pysnmp import debug debug.setDebug(debug.Debug(‘msgproc’)) -ilya > On 06 Nov 2015, at 22:21, Diego Muñoz <dmu...@gm...> wrote: > > Hi Ilya, I am using the correct community, and I could successfully change the image with this code: > > from pysnmp.entity.rfc3413.oneliner import cmdgen > from pysnmp.proto.rfc1902 import OctetString > > device_ip = '192.168.1.222' > port = 6000 > > cmdGen = cmdgen.CommandGenerator() > > a = '\xff\xff\xff\x03\x00\x3c\x2f\xf5\x00\x00\x00\x00' > > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( > cmdgen.CommunityData('public'), > cmdgen.UdpTransportTarget((device_ip, port)), > ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), > lookupNames=True, lookupValues=True > ) > > I could finally understand the bytes in the sequence and get the OID of the object and the Octet String argument that I have to provide. This octet string (variable "a" in the code I wrote) contains 6 parameters, including the type of memory (03) and the memory number that corresponds to the image (00 3c). > > Now, what I don't get is why the new code works, when the only difference is the way I refer to the function I call: > > Code that does not work: > (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), > OctetString(a)), > > Code that works: > ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), > > > 2015-11-06 17:29 GMT-03:00 Ilya Etingof <il...@gl... <mailto:il...@gl...>>: > > Hi Diego, > > Make sure you are using correct community name, for SET queries it is frequently defaulted to ‘private’. > > If you show me the byte-string that works, I can possibly come up with corresponding SNMP message. > > -ilya > > > On 05 Nov 2015, at 17:02, Diego Muñoz <dmu...@gm... <mailto:dmu...@gm...>> wrote: > > > > Hello everyone, > > > > I have been working with NTCIP for only one week, and I need to change an image on a device by sending a SNMP activation message. I have been given the corresponding MIB, and a byte sequence of a SNMP message. > > > > I recently understood how the sequence is formed, and its components. I identified the MIB OID to activate the image, and identified the parameters that I need to give to the function. By editing the byte sequence, I can successfully send the message and change the image with python sockets using UDP. I also can successfully get information from the device with PySNMP and the getCmd function. > > > > The problem I have is that I try to setCmd the message and I only get a Timeout from the device. This is the code of my setCmd > > > > from pysnmp.entity.rfc3413.oneliner import cmdgen > > from pysnmp.proto.rfc1902 import OctetString > > > > device_ip = '192.168.1.222' > > port = 6000 > > > > cmdGen = cmdgen.CommandGenerator() > > > > # this variable includes the parameters I need to send to the device > > a = '\xff\xff\xff\x03\x00\x0a\x2f\xf5\x00\x00\x00\x00' > > > > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( > > cmdgen.CommunityData('public'), > > cmdgen.UdpTransportTarget((device_ip, port)), > > (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), > > OctetString(a)), > > lookupNames=True, lookupValues=True > > ) > > > > I don't know which part is wrong, I would appreciate any help. > > Regards, > > Diego > > > |
From: Diego M. <dmu...@gm...> - 2015-11-06 21:21:40
|
Hi Ilya, I am using the correct community, and I could successfully change the image with this code: from pysnmp.entity.rfc3413.oneliner import cmdgen from pysnmp.proto.rfc1902 import OctetString device_ip = '192.168.1.222' port = 6000 cmdGen = cmdgen.CommandGenerator() a = '\xff\xff\xff\x03\x00\x3c\x2f\xf5\x00\x00\x00\x00' errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( cmdgen.CommunityData('public'), cmdgen.UdpTransportTarget((device_ip, port)), ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), lookupNames=True, lookupValues=True ) I could finally understand the bytes in the sequence and get the OID of the object and the Octet String argument that I have to provide. This octet string (variable "a" in the code I wrote) contains 6 parameters, including the type of memory (03) and the memory number that corresponds to the image (00 3c). Now, what I don't get is why the new code works, when the only difference is the way I refer to the function I call: Code that does not work: (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), OctetString(a)), Code that works: ('1.3.6.1.4.1.1206.4.2.3.6.3.0', OctetString(a)), 2015-11-06 17:29 GMT-03:00 Ilya Etingof <il...@gl...>: > > Hi Diego, > > Make sure you are using correct community name, for SET queries it is > frequently defaulted to ‘private’. > > If you show me the byte-string that works, I can possibly come up with > corresponding SNMP message. > > -ilya > > > On 05 Nov 2015, at 17:02, Diego Muñoz <dmu...@gm...> wrote: > > > > Hello everyone, > > > > I have been working with NTCIP for only one week, and I need to change > an image on a device by sending a SNMP activation message. I have been > given the corresponding MIB, and a byte sequence of a SNMP message. > > > > I recently understood how the sequence is formed, and its components. I > identified the MIB OID to activate the image, and identified the parameters > that I need to give to the function. By editing the byte sequence, I can > successfully send the message and change the image with python sockets > using UDP. I also can successfully get information from the device with > PySNMP and the getCmd function. > > > > The problem I have is that I try to setCmd the message and I only get a > Timeout from the device. This is the code of my setCmd > > > > from pysnmp.entity.rfc3413.oneliner import cmdgen > > from pysnmp.proto.rfc1902 import OctetString > > > > device_ip = '192.168.1.222' > > port = 6000 > > > > cmdGen = cmdgen.CommandGenerator() > > > > # this variable includes the parameters I need to send to the device > > a = '\xff\xff\xff\x03\x00\x0a\x2f\xf5\x00\x00\x00\x00' > > > > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( > > cmdgen.CommunityData('public'), > > cmdgen.UdpTransportTarget((device_ip, port)), > > (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), > > OctetString(a)), > > lookupNames=True, lookupValues=True > > ) > > > > I don't know which part is wrong, I would appreciate any help. > > Regards, > > Diego > > > |
From: Ilya E. <il...@gl...> - 2015-11-06 20:29:24
|
Hi Diego, Make sure you are using correct community name, for SET queries it is frequently defaulted to ‘private’. If you show me the byte-string that works, I can possibly come up with corresponding SNMP message. -ilya > On 05 Nov 2015, at 17:02, Diego Muñoz <dmu...@gm...> wrote: > > Hello everyone, > > I have been working with NTCIP for only one week, and I need to change an image on a device by sending a SNMP activation message. I have been given the corresponding MIB, and a byte sequence of a SNMP message. > > I recently understood how the sequence is formed, and its components. I identified the MIB OID to activate the image, and identified the parameters that I need to give to the function. By editing the byte sequence, I can successfully send the message and change the image with python sockets using UDP. I also can successfully get information from the device with PySNMP and the getCmd function. > > The problem I have is that I try to setCmd the message and I only get a Timeout from the device. This is the code of my setCmd > > from pysnmp.entity.rfc3413.oneliner import cmdgen > from pysnmp.proto.rfc1902 import OctetString > > device_ip = '192.168.1.222' > port = 6000 > > cmdGen = cmdgen.CommandGenerator() > > # this variable includes the parameters I need to send to the device > a = '\xff\xff\xff\x03\x00\x0a\x2f\xf5\x00\x00\x00\x00' > > errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( > cmdgen.CommunityData('public'), > cmdgen.UdpTransportTarget((device_ip, port)), > (cmdgen.MibVariable('NTCIP1203_v03_38', 'dmsActivateMessage', 0), > OctetString(a)), > lookupNames=True, lookupValues=True > ) > > I don't know which part is wrong, I would appreciate any help. > Regards, > Diego |