pysnmp-users Mailing List for SNMP library for Python (Page 9)
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-03-16 10:33:21
|
Hi Tom, You can check it like this: from pyasn1.type.univ import OctetString if isinstance(val, OctetString): val = str(val) ... The str() part is important because you are getting pyasn1 objects in response while "re" expects strings. -ilya On 03/16/2015 01:15 PM, Tom Kr. wrote: > Some good news to the beginning of the new week. > After I changed the method from .getVarBindsList() to .getVarBinds(), I can read the data with the stupid line feed. > > Now I tried to search and replace the line feed with this lines > for oid, val in varBinds: > print("DEBUG_oid: %s" % oid) > print("DEUBG_val: %s" % val) > new_val = "".join(val) > val = re.sub(r"[\r|\s]", "", new_val) > print("DEBUG_oid_2: %s" % oid) > print("DEBUG_val_2: %s" % val) > > Each time there is a trap with this characters I get this error message. > return _compile(pattern, flags).sub(repl, string, count) > ;TypeError: expected string or buffer > > How can I find out which type the val variable have? > And how can I change this to string? > > Tom > > > >> Am 12.03.2015 um 16:18 schrieb Ilya Etingof <il...@gl...>: >> >> >> Right, in 'val' you are getting the whole SNMP PDU value structure, not just a leaf scalar. That's the reason it does not match OctetString class instance check. >> >> Use .getVarBinds() method instead of .getVarBindsList(). The former returns a list of tuples of terminal values, while the latter returns original var-bindings list from SNMP PDU which always holds a record-like structure for value. >> >> -ilya >> >>> On 03/12/2015 05:29 PM, Tom Kr. wrote: >>> Hmm, I'm confused. >>> With this changes I also get hex values back and I still enter the else part for each value. >>> import sys,os >>> sys.path.append('/usr/share/pyshared/') >>> from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher >>> from pysnmp.carrier.asynsock.dgram import udp, udp6 >>> from pyasn1.codec.ber import decoder >>> from pysnmp.proto import api >>> #from pysnmp.proto.rfc1902 import OctetString >>> from pyasn1.type.univ import OctetString >>> def pySnmpCheck(oval): >>> if isinstance(oval, OctetString): >>> print("DEBUG: OctetString") >>> val = oval.asOctets() >>> else: >>> print("DEBUG: else") >>> val = oval >>> return val >>> If this information are useful, this is the header I've got. >>> # python snmp-transports.py >>> Notification message from (1, 3, 6, 1, 6, 1, 1):('xxx.xxx.xxx.xxx', 52032): >>> Enterprise: 1.3.6.1.4.1.18494.2 >>> Agent Address: xxx.xxx.xxx.xxx >>> Generic Trap: 'enterpriseSpecific' >>> Specific Trap: 1 >>> Uptime: 1 >>> Var-binds: >>> DEBUG: else >>> 1.3.6.1.4.1.18494.2.1.9 = ObjectSyntax: >>> simple=SimpleSyntax: >>> string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 >>> Tom >>> >>> >>> >>>> Am 12.03.2015 um 14:39 schrieb Ilya Etingof <il...@gl...>: >>>> >>>> >>>> Oh, if you are using SNMPv1 you should check against the base class: >>>> >>>> from pyasn1.type.univ import OctetString >>>> >>>> if isinstance(oval, OctetString): >>>> ... >>>> >>>> Perhaps this should be improved in pysnmp. >>>> >>>> -ilya >>>> >>>>> On 03/12/2015 04:29 PM, Tom Kr. wrote: >>>>> I made the following changes to the script. >>>>> ... >>>>> from pysnmp.proto.rfc1902 import OctetString >>>>> def pySnmpCheck(oval): >>>>> if isinstance(oval, OctetString): >>>>> print("DEBUG: OctetString") >>>>> val = oval.asOctets() >>>>> else: >>>>> print("DEBUG: else") >>>>> val = oval >>>>> return val >>>>> ... >>>>> for oid, val in varBinds: >>>>> val = pySnmpCheck(val) >>>>> print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) >>>>> ... >>>>> Then I start grabbing the snmp messages again. >>>>> Unfortunately every value of the message go through the else part. >>>>> But how could this happen? >>>>> Is there a possibility to check which type of string the values have? >>>>> Tom >>>>> >>>>> >>>>> >>>>>> Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: >>>>>> >>>>>> >>>>>> That's right, .asOctets() is only defined for OctetString type and its >>>>>> subclasses. Therefore, to deal with octets of OctetString() you should >>>>>> do additional check: >>>>>> >>>>>> from pysnmp.proto.rfc1902 import OctetString >>>>>> >>>>>> ... >>>>>> >>>>>> if isinstance(val, OctetString): >>>>>> val = val.asOctets() >>>>>> >>>>>> Keep in mind that octet string is not always the same as printable >>>>>> string. The former is not immune to your terminal potentially eating >>>>>> non-printable characters or garbling output in a funny way. Also, text >>>>>> encoding is not defined by OctetString. To be on a safe side default >>>>>> OctetString printout is done in hex whenever a non-printable is seen in >>>>>> its contents. >>>>>> >>>>>> -ilya >>>>>> >>>>>>>> On 03/11/2015 03:18 PM, Craig Small wrote: >>>>>>>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>>>>>>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >>>>>>> Are you sure each row is returning something asOctets makes sense for? >>>>>>> An Integer doesn't make sense. >>>>>>> >>>>>>>> Does it only works if a hex value is send by snmp? >>>>>>> I believe it works for certain types of values, such as an OctetString >>>>>>> >>>>>>>> How can I check if the value is hex or not? >>>>>>> Not sure, but the types are found in pyasn1.type.univ so you could >>>>>>> compare it to, say, univ.OctetString >>>>>>> >>>>>>> ObjectSyntax seems to be the superset of all types, from what I can tell >>>>>>> it means pysnmp wasn't sure what the type should be. >>>>>>> >>>>>>> It's been an interesting and educational discussion anyhow. >>>>>>> >>>>>>> - Craig |
From: Tom Kr. <to...@we...> - 2015-03-16 10:16:04
|
Some good news to the beginning of the new week. After I changed the method from .getVarBindsList() to .getVarBinds(), I can read the data with the stupid line feed. Now I tried to search and replace the line feed with this lines for oid, val in varBinds: print("DEBUG_oid: %s" % oid) print("DEUBG_val: %s" % val) new_val = "".join(val) val = re.sub(r"[\r|\s]", "", new_val) print("DEBUG_oid_2: %s" % oid) print("DEBUG_val_2: %s" % val) Each time there is a trap with this characters I get this error message. return _compile(pattern, flags).sub(repl, string, count) ;TypeError: expected string or buffer How can I find out which type the val variable have? And how can I change this to string? Tom > Am 12.03.2015 um 16:18 schrieb Ilya Etingof <il...@gl...>: > > > Right, in 'val' you are getting the whole SNMP PDU value structure, not just a leaf scalar. That's the reason it does not match OctetString class instance check. > > Use .getVarBinds() method instead of .getVarBindsList(). The former returns a list of tuples of terminal values, while the latter returns original var-bindings list from SNMP PDU which always holds a record-like structure for value. > > -ilya > >> On 03/12/2015 05:29 PM, Tom Kr. wrote: >> Hmm, I'm confused. >> With this changes I also get hex values back and I still enter the else part for each value. >> import sys,os >> sys.path.append('/usr/share/pyshared/') >> from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher >> from pysnmp.carrier.asynsock.dgram import udp, udp6 >> from pyasn1.codec.ber import decoder >> from pysnmp.proto import api >> #from pysnmp.proto.rfc1902 import OctetString >> from pyasn1.type.univ import OctetString >> def pySnmpCheck(oval): >> if isinstance(oval, OctetString): >> print("DEBUG: OctetString") >> val = oval.asOctets() >> else: >> print("DEBUG: else") >> val = oval >> return val >> If this information are useful, this is the header I've got. >> # python snmp-transports.py >> Notification message from (1, 3, 6, 1, 6, 1, 1):('xxx.xxx.xxx.xxx', 52032): >> Enterprise: 1.3.6.1.4.1.18494.2 >> Agent Address: xxx.xxx.xxx.xxx >> Generic Trap: 'enterpriseSpecific' >> Specific Trap: 1 >> Uptime: 1 >> Var-binds: >> DEBUG: else >> 1.3.6.1.4.1.18494.2.1.9 = ObjectSyntax: >> simple=SimpleSyntax: >> string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 >> Tom >> >> >> >>> Am 12.03.2015 um 14:39 schrieb Ilya Etingof <il...@gl...>: >>> >>> >>> Oh, if you are using SNMPv1 you should check against the base class: >>> >>> from pyasn1.type.univ import OctetString >>> >>> if isinstance(oval, OctetString): >>> ... >>> >>> Perhaps this should be improved in pysnmp. >>> >>> -ilya >>> >>>> On 03/12/2015 04:29 PM, Tom Kr. wrote: >>>> I made the following changes to the script. >>>> ... >>>> from pysnmp.proto.rfc1902 import OctetString >>>> def pySnmpCheck(oval): >>>> if isinstance(oval, OctetString): >>>> print("DEBUG: OctetString") >>>> val = oval.asOctets() >>>> else: >>>> print("DEBUG: else") >>>> val = oval >>>> return val >>>> ... >>>> for oid, val in varBinds: >>>> val = pySnmpCheck(val) >>>> print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) >>>> ... >>>> Then I start grabbing the snmp messages again. >>>> Unfortunately every value of the message go through the else part. >>>> But how could this happen? >>>> Is there a possibility to check which type of string the values have? >>>> Tom >>>> >>>> >>>> >>>>> Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: >>>>> >>>>> >>>>> That's right, .asOctets() is only defined for OctetString type and its >>>>> subclasses. Therefore, to deal with octets of OctetString() you should >>>>> do additional check: >>>>> >>>>> from pysnmp.proto.rfc1902 import OctetString >>>>> >>>>> ... >>>>> >>>>> if isinstance(val, OctetString): >>>>> val = val.asOctets() >>>>> >>>>> Keep in mind that octet string is not always the same as printable >>>>> string. The former is not immune to your terminal potentially eating >>>>> non-printable characters or garbling output in a funny way. Also, text >>>>> encoding is not defined by OctetString. To be on a safe side default >>>>> OctetString printout is done in hex whenever a non-printable is seen in >>>>> its contents. >>>>> >>>>> -ilya >>>>> >>>>>>> On 03/11/2015 03:18 PM, Craig Small wrote: >>>>>>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>>>>>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >>>>>> Are you sure each row is returning something asOctets makes sense for? >>>>>> An Integer doesn't make sense. >>>>>> >>>>>>> Does it only works if a hex value is send by snmp? >>>>>> I believe it works for certain types of values, such as an OctetString >>>>>> >>>>>>> How can I check if the value is hex or not? >>>>>> Not sure, but the types are found in pyasn1.type.univ so you could >>>>>> compare it to, say, univ.OctetString >>>>>> >>>>>> ObjectSyntax seems to be the superset of all types, from what I can tell >>>>>> it means pysnmp wasn't sure what the type should be. >>>>>> >>>>>> It's been an interesting and educational discussion anyhow. >>>>>> >>>>>> - Craig > |
From: Ilya E. <il...@gl...> - 2015-03-12 15:18:35
|
Right, in 'val' you are getting the whole SNMP PDU value structure, not just a leaf scalar. That's the reason it does not match OctetString class instance check. Use .getVarBinds() method instead of .getVarBindsList(). The former returns a list of tuples of terminal values, while the latter returns original var-bindings list from SNMP PDU which always holds a record-like structure for value. -ilya On 03/12/2015 05:29 PM, Tom Kr. wrote: > Hmm, I'm confused. > With this changes I also get hex values back and I still enter the else part for each value. > > import sys,os > > sys.path.append('/usr/share/pyshared/') > > from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher > from pysnmp.carrier.asynsock.dgram import udp, udp6 > from pyasn1.codec.ber import decoder > from pysnmp.proto import api > #from pysnmp.proto.rfc1902 import OctetString > from pyasn1.type.univ import OctetString > > def pySnmpCheck(oval): > if isinstance(oval, OctetString): > print("DEBUG: OctetString") > val = oval.asOctets() > else: > print("DEBUG: else") > val = oval > return val > > If this information are useful, this is the header I've got. > > # python snmp-transports.py > Notification message from (1, 3, 6, 1, 6, 1, 1):('xxx.xxx.xxx.xxx', 52032): > Enterprise: 1.3.6.1.4.1.18494.2 > Agent Address: xxx.xxx.xxx.xxx > Generic Trap: 'enterpriseSpecific' > Specific Trap: 1 > Uptime: 1 > Var-binds: > DEBUG: else > 1.3.6.1.4.1.18494.2.1.9 = ObjectSyntax: > simple=SimpleSyntax: > string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 > > Tom > > > > > >> Am 12.03.2015 um 14:39 schrieb Ilya Etingof <il...@gl...>: >> >> >> Oh, if you are using SNMPv1 you should check against the base class: >> >> from pyasn1.type.univ import OctetString >> >> if isinstance(oval, OctetString): >> ... >> >> Perhaps this should be improved in pysnmp. >> >> -ilya >> >>> On 03/12/2015 04:29 PM, Tom Kr. wrote: >>> I made the following changes to the script. >>> ... >>> from pysnmp.proto.rfc1902 import OctetString >>> def pySnmpCheck(oval): >>> if isinstance(oval, OctetString): >>> print("DEBUG: OctetString") >>> val = oval.asOctets() >>> else: >>> print("DEBUG: else") >>> val = oval >>> return val >>> ... >>> for oid, val in varBinds: >>> val = pySnmpCheck(val) >>> print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) >>> ... >>> Then I start grabbing the snmp messages again. >>> Unfortunately every value of the message go through the else part. >>> But how could this happen? >>> Is there a possibility to check which type of string the values have? >>> Tom >>> >>> >>> >>>> Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: >>>> >>>> >>>> That's right, .asOctets() is only defined for OctetString type and its >>>> subclasses. Therefore, to deal with octets of OctetString() you should >>>> do additional check: >>>> >>>> from pysnmp.proto.rfc1902 import OctetString >>>> >>>> ... >>>> >>>> if isinstance(val, OctetString): >>>> val = val.asOctets() >>>> >>>> Keep in mind that octet string is not always the same as printable >>>> string. The former is not immune to your terminal potentially eating >>>> non-printable characters or garbling output in a funny way. Also, text >>>> encoding is not defined by OctetString. To be on a safe side default >>>> OctetString printout is done in hex whenever a non-printable is seen in >>>> its contents. >>>> >>>> -ilya >>>> >>>>>> On 03/11/2015 03:18 PM, Craig Small wrote: >>>>>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>>>>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >>>>> Are you sure each row is returning something asOctets makes sense for? >>>>> An Integer doesn't make sense. >>>>> >>>>>> Does it only works if a hex value is send by snmp? >>>>> I believe it works for certain types of values, such as an OctetString >>>>> >>>>>> How can I check if the value is hex or not? >>>>> Not sure, but the types are found in pyasn1.type.univ so you could >>>>> compare it to, say, univ.OctetString >>>>> >>>>> ObjectSyntax seems to be the superset of all types, from what I can tell >>>>> it means pysnmp wasn't sure what the type should be. >>>>> >>>>> It's been an interesting and educational discussion anyhow. >>>>> >>>>> - Craig |
From: Tom Kr. <to...@we...> - 2015-03-12 14:29:57
|
Hmm, I'm confused. With this changes I also get hex values back and I still enter the else part for each value. import sys,os sys.path.append('/usr/share/pyshared/') from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher from pysnmp.carrier.asynsock.dgram import udp, udp6 from pyasn1.codec.ber import decoder from pysnmp.proto import api #from pysnmp.proto.rfc1902 import OctetString from pyasn1.type.univ import OctetString def pySnmpCheck(oval): if isinstance(oval, OctetString): print("DEBUG: OctetString") val = oval.asOctets() else: print("DEBUG: else") val = oval return val If this information are useful, this is the header I've got. # python snmp-transports.py Notification message from (1, 3, 6, 1, 6, 1, 1):('xxx.xxx.xxx.xxx', 52032): Enterprise: 1.3.6.1.4.1.18494.2 Agent Address: xxx.xxx.xxx.xxx Generic Trap: 'enterpriseSpecific' Specific Trap: 1 Uptime: 1 Var-binds: DEBUG: else 1.3.6.1.4.1.18494.2.1.9 = ObjectSyntax: simple=SimpleSyntax: string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 Tom > Am 12.03.2015 um 14:39 schrieb Ilya Etingof <il...@gl...>: > > > Oh, if you are using SNMPv1 you should check against the base class: > > from pyasn1.type.univ import OctetString > > if isinstance(oval, OctetString): > ... > > Perhaps this should be improved in pysnmp. > > -ilya > >> On 03/12/2015 04:29 PM, Tom Kr. wrote: >> I made the following changes to the script. >> ... >> from pysnmp.proto.rfc1902 import OctetString >> def pySnmpCheck(oval): >> if isinstance(oval, OctetString): >> print("DEBUG: OctetString") >> val = oval.asOctets() >> else: >> print("DEBUG: else") >> val = oval >> return val >> ... >> for oid, val in varBinds: >> val = pySnmpCheck(val) >> print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) >> ... >> Then I start grabbing the snmp messages again. >> Unfortunately every value of the message go through the else part. >> But how could this happen? >> Is there a possibility to check which type of string the values have? >> Tom >> >> >> >>> Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: >>> >>> >>> That's right, .asOctets() is only defined for OctetString type and its >>> subclasses. Therefore, to deal with octets of OctetString() you should >>> do additional check: >>> >>> from pysnmp.proto.rfc1902 import OctetString >>> >>> ... >>> >>> if isinstance(val, OctetString): >>> val = val.asOctets() >>> >>> Keep in mind that octet string is not always the same as printable >>> string. The former is not immune to your terminal potentially eating >>> non-printable characters or garbling output in a funny way. Also, text >>> encoding is not defined by OctetString. To be on a safe side default >>> OctetString printout is done in hex whenever a non-printable is seen in >>> its contents. >>> >>> -ilya >>> >>>>> On 03/11/2015 03:18 PM, Craig Small wrote: >>>>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>>>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >>>> Are you sure each row is returning something asOctets makes sense for? >>>> An Integer doesn't make sense. >>>> >>>>> Does it only works if a hex value is send by snmp? >>>> I believe it works for certain types of values, such as an OctetString >>>> >>>>> How can I check if the value is hex or not? >>>> Not sure, but the types are found in pyasn1.type.univ so you could >>>> compare it to, say, univ.OctetString >>>> >>>> ObjectSyntax seems to be the superset of all types, from what I can tell >>>> it means pysnmp wasn't sure what the type should be. >>>> >>>> It's been an interesting and educational discussion anyhow. >>>> >>>> - Craig >>> > |
From: Ilya E. <il...@gl...> - 2015-03-12 13:40:01
|
Oh, if you are using SNMPv1 you should check against the base class: from pyasn1.type.univ import OctetString if isinstance(oval, OctetString): ... Perhaps this should be improved in pysnmp. -ilya On 03/12/2015 04:29 PM, Tom Kr. wrote: > I made the following changes to the script. > > ... > from pysnmp.proto.rfc1902 import OctetString > > def pySnmpCheck(oval): > if isinstance(oval, OctetString): > print("DEBUG: OctetString") > val = oval.asOctets() > else: > print("DEBUG: else") > val = oval > return val > > ... > for oid, val in varBinds: > val = pySnmpCheck(val) > print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) > ... > > Then I start grabbing the snmp messages again. > Unfortunately every value of the message go through the else part. > But how could this happen? > > Is there a possibility to check which type of string the values have? > > Tom > > > >> Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: >> >> >> That's right, .asOctets() is only defined for OctetString type and its >> subclasses. Therefore, to deal with octets of OctetString() you should >> do additional check: >> >> from pysnmp.proto.rfc1902 import OctetString >> >> ... >> >> if isinstance(val, OctetString): >> val = val.asOctets() >> >> Keep in mind that octet string is not always the same as printable >> string. The former is not immune to your terminal potentially eating >> non-printable characters or garbling output in a funny way. Also, text >> encoding is not defined by OctetString. To be on a safe side default >> OctetString printout is done in hex whenever a non-printable is seen in >> its contents. >> >> -ilya >> >>> On 03/11/2015 03:18 PM, Craig Small wrote: >>>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >>> Are you sure each row is returning something asOctets makes sense for? >>> An Integer doesn't make sense. >>> >>>> Does it only works if a hex value is send by snmp? >>> I believe it works for certain types of values, such as an OctetString >>> >>>> How can I check if the value is hex or not? >>> Not sure, but the types are found in pyasn1.type.univ so you could >>> compare it to, say, univ.OctetString >>> >>> ObjectSyntax seems to be the superset of all types, from what I can tell >>> it means pysnmp wasn't sure what the type should be. >>> >>> It's been an interesting and educational discussion anyhow. >>> >>> - Craig >> |
From: Tom Kr. <to...@we...> - 2015-03-12 13:29:33
|
I made the following changes to the script. ... from pysnmp.proto.rfc1902 import OctetString def pySnmpCheck(oval): if isinstance(oval, OctetString): print("DEBUG: OctetString") val = oval.asOctets() else: print("DEBUG: else") val = oval return val ... for oid, val in varBinds: val = pySnmpCheck(val) print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) ... Then I start grabbing the snmp messages again. Unfortunately every value of the message go through the else part. But how could this happen? Is there a possibility to check which type of string the values have? Tom > Am 11.03.2015 um 14:17 schrieb Ilya Etingof <il...@gl...>: > > > That's right, .asOctets() is only defined for OctetString type and its > subclasses. Therefore, to deal with octets of OctetString() you should > do additional check: > > from pysnmp.proto.rfc1902 import OctetString > > ... > > if isinstance(val, OctetString): > val = val.asOctets() > > Keep in mind that octet string is not always the same as printable > string. The former is not immune to your terminal potentially eating > non-printable characters or garbling output in a funny way. Also, text > encoding is not defined by OctetString. To be on a safe side default > OctetString printout is done in hex whenever a non-printable is seen in > its contents. > > -ilya > >> On 03/11/2015 03:18 PM, Craig Small wrote: >>> On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >>> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' >> Are you sure each row is returning something asOctets makes sense for? >> An Integer doesn't make sense. >> >>> Does it only works if a hex value is send by snmp? >> I believe it works for certain types of values, such as an OctetString >> >>> How can I check if the value is hex or not? >> Not sure, but the types are found in pyasn1.type.univ so you could >> compare it to, say, univ.OctetString >> >> ObjectSyntax seems to be the superset of all types, from what I can tell >> it means pysnmp wasn't sure what the type should be. >> >> It's been an interesting and educational discussion anyhow. >> >> - Craig > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming The Go Parallel Website, sponsored > by Intel and developed in partnership with Slashdot Media, is your hub for all > things parallel software development, from weekly thought leadership blogs to > news, videos, case studies, tutorials and more. Take a look and join the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Ilya E. <il...@gl...> - 2015-03-11 13:17:31
|
That's right, .asOctets() is only defined for OctetString type and its subclasses. Therefore, to deal with octets of OctetString() you should do additional check: from pysnmp.proto.rfc1902 import OctetString ... if isinstance(val, OctetString): val = val.asOctets() Keep in mind that octet string is not always the same as printable string. The former is not immune to your terminal potentially eating non-printable characters or garbling output in a funny way. Also, text encoding is not defined by OctetString. To be on a safe side default OctetString printout is done in hex whenever a non-printable is seen in its contents. -ilya On 03/11/2015 03:18 PM, Craig Small wrote: > On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: >> ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' > Are you sure each row is returning something asOctets makes sense for? > An Integer doesn't make sense. > >> Does it only works if a hex value is send by snmp? > I believe it works for certain types of values, such as an OctetString > >> How can I check if the value is hex or not? > Not sure, but the types are found in pyasn1.type.univ so you could > compare it to, say, univ.OctetString > > ObjectSyntax seems to be the superset of all types, from what I can tell > it means pysnmp wasn't sure what the type should be. > > It's been an interesting and educational discussion anyhow. > > - Craig |
From: Craig S. <cs...@en...> - 2015-03-11 12:36:48
|
On Wed, Mar 11, 2015 at 07:02:44AM +0100, Tom wrote: > ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' Are you sure each row is returning something asOctets makes sense for? An Integer doesn't make sense. > Does it only works if a hex value is send by snmp? I believe it works for certain types of values, such as an OctetString > How can I check if the value is hex or not? Not sure, but the types are found in pyasn1.type.univ so you could compare it to, say, univ.OctetString ObjectSyntax seems to be the superset of all types, from what I can tell it means pysnmp wasn't sure what the type should be. It's been an interesting and educational discussion anyhow. - Craig -- 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: Tom <to...@we...> - 2015-03-11 06:02:56
|
Hi -ilya, thanks for the quick answer. Your solution sounds great but unfortunately I have some troubles with the implementation. I changed the script as follows: ... print('Var-binds:') result = {} for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) result[oid] = val.asOctets() print('%s = %s' % (oid.prettyPrint(), result.prettyPrint())) ... When I run the script and send some test data via snmp to the server I got this error message. Traceback (most recent call last): File "snmp-transports.py", line 115, in <module> transportDispatcher.runDispatcher() File "/usr/lib/python2.7/dist-packages/pysnmp/carrier/asynsock/dispatch.py", line 41, in runDispatcher raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info()))) pysnmp.error.PySnmpError: poll error: Traceback (most recent call last): ; File "/usr/lib/python2.7/dist-packages/pysnmp/carrier/asynsock/dispatch.py", line 37, in runDispatcher use_poll=True, map=self.__sockMap, count=1) ; File "/usr/lib/python2.7/asyncore.py", line 220, in loop poll_fun(timeout, map) ; File "/usr/lib/python2.7/asyncore.py", line 201, in poll2 readwrite(obj, flags) ; File "/usr/lib/python2.7/asyncore.py", line 123, in readwrite obj.handle_error() ; File "/usr/lib/python2.7/asyncore.py", line 108, in readwrite obj.handle_read_event() ; File "/usr/lib/python2.7/asyncore.py", line 449, in handle_read_event self.handle_read() ; File "/usr/lib/python2.7/dist-packages/pysnmp/carrier/asynsock/dgram/base.py", line 83, in handle_read self._cbFun(self, transportAddress, incomingMessage) ; File "/usr/lib/python2.7/dist-packages/pysnmp/carrier/base.py", line 52, in _cbFun self, transportDomain, transportAddress, incomingMessage ; File "snmp-transports.py", line 59, in trapCallback result[oid] = val.asOctets() ;AttributeError: ObjectSyntax instance has no attribute 'asOctets' Where is my mistake? Does it only works if a hex value is send by snmp? How can I check if the value is hex or not? Sorry for the stupid questions but I'm really new to python and their modules. Kind regards, Tom > Am 10.03.2015 um 07:03 schrieb Ilya Etingof <il...@gl...>: > > Hi Tom, > > The OctetString type prints its contents in hex form if there’s a potentially non-printable characters there that may be lost when printing to the terminal. Use .asOctets() method to retrieve data in pure octet-string form: > > >>> s = OctetString(hexValue='4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858') > >>> s.prettyPrint() > '0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858' > >>> s.asOctets() > "Operator XXXXXXXXXX : XXXXXXXXXX, XXXXXXX , Locally authenticated - successfully signed on to the terminal 'XXX.XXX.X.X@X' at 14:28 using 'XXXXXXXX XXX XXXXXXXX'.\nOperator Profiles: XXXXXXXXXXXXX" > > -ilya > >> On 09 Mar 2015, at 22:23, Tom Kr. <to...@we...> wrote: >> >> >> Hi there, >> >> I'm new to this mailing list and I have a issue with the pysnmp / pyasn1 module. >> I use python with version 3.4 and pysnmp with version 4.2.5. >> The OS is Ubuntu server 14.04.2. >> >> # lsb_release -a >> No LSB modules are available. >> Distributor ID: Ubuntu >> Description: Ubuntu 14.04.2 LTS >> Release: 14.04 >> Codename: trusty >> >> ii python-pysnmp4 4.2.5-1 all Python SNMP library for agents and managers (Python 2 module) >> ii python-pyasn1 0.1.7-1ubuntu2 all ASN.1 library for Python (Python 2 module) >> ii python3.4 3.4.0-2ubuntu1 amd64 Interactive high-level object-oriented language (version 3.4) >> >> I try to use the following script to read snmp traps and print this traps on the screen. >> But unfortunately I have some troubles with multi-line traps. >> This traps are only shown as hex values. >> I think the problem is the decoder but I'm not very familiar with python and also not with pysnmp. >> >> I hope someone of you can help me or give me some ideas what I should do next. >> For the moment I have no idea. >> >> The script: >> ---------------------------------------------------------------------------------------------- >> import sys,os >> >> sys.path.append('/usr/share/pyshared/') >> >> from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher >> from pysnmp.carrier.asynsock.dgram import udp, udp6 >> from pyasn1.codec.ber import decoder >> from pysnmp.proto import api >> >> def trapCallback(transportDispatcher, transportDomain, transportAddress, wholeMsg): >> while wholeMsg: >> msgVer = int(api.decodeMessageVersion(wholeMsg)) >> if msgVer in api.protoModules: >> pMod = api.protoModules[msgVer] >> else: >> print('Unsupported SNMP version %s' % msgVer) >> return >> reqMsg, wholeMsg = decoder.decode( >> wholeMsg, asn1Spec=pMod.Message(), >> ) >> print('Notification message from %s:%s: ' % ( >> transportDomain, transportAddress >> ) >> ) >> reqPDU = pMod.apiMessage.getPDU(reqMsg) >> if reqPDU.isSameTypeWith(pMod.TrapPDU()): >> if msgVer == api.protoVersion1: >> print('Enterprise: %s' % ( >> pMod.apiTrapPDU.getEnterprise(reqPDU).prettyPrint() >> ) >> ) >> print('Agent Address: %s' % ( >> pMod.apiTrapPDU.getAgentAddr(reqPDU).prettyPrint() >> ) >> ) >> print('Generic Trap: %s' % ( >> pMod.apiTrapPDU.getGenericTrap(reqPDU).prettyPrint() >> ) >> ) >> print('Specific Trap: %s' % ( >> pMod.apiTrapPDU.getSpecificTrap(reqPDU).prettyPrint() >> ) >> ) >> print('Uptime: %s' % ( >> pMod.apiTrapPDU.getTimeStamp(reqPDU).prettyPrint() >> ) >> ) >> varBinds = pMod.apiTrapPDU.getVarBindList(reqPDU) >> else: >> varBinds = pMod.apiPDU.getVarBindList(reqPDU) >> print('Var-binds:') >> for oid, val in varBinds: >> print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) >> return wholeMsg >> >> transportDispatcher = AsynsockDispatcher() >> >> transportDispatcher.registerRecvCbFun(trapCallback) >> >> # UDP/IPv4 >> transportDispatcher.registerTransport( >> udp.domainName, udp.UdpSocketTransport().openServerMode(('localhost', 162)) >> ) >> >> # UDP/IPv6 >> transportDispatcher.registerTransport( >> udp6.domainName, udp6.Udp6SocketTransport().openServerMode(('::1', 162)) >> ) >> >> transportDispatcher.jobStarted(1) >> >> try: >> # Dispatcher will never finish as job#1 never reaches zero >> transportDispatcher.runDispatcher() >> except: >> transportDispatcher.closeDispatcher() >> raise >> ---------------------------------------------------------------------------------------------- >> >> >> As you can see, the script is an example from the project side. >> (http://pysnmp.sourceforge.net/examples/current/v1arch/manager/ntfrcv/v2c-multiple-transports.html) >> >> This is the part of the trap where the hex value is shown instead of the plain text. >> string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 >> >> This is the message I would expect. >> "Operator XXXXXXXXXX : XXXXXXXXXX, XXXXXXX , Locally authenticated - successfully signed on to the terminal 'XXX.XXX.X.X@X' at 14:28using 'XXXXXXXX XXX XXXXXXXX'. >> Operator Profiles: XXXXXXXXXXXXX" >> >> For me, the problem is located at the line feed. Is there a possibility to replace any line feed character with a space or nothing? >> I think this should be done in the pyasn1 module, but I don't know how. >> >> Hope somebody can help me with my problem. >> >> Kind regards, >> Tom >> > |
From: Ilya E. <il...@gl...> - 2015-03-10 06:03:20
|
Hi Tom, The OctetString type prints its contents in hex form if there’s a potentially non-printable characters there that may be lost when printing to the terminal. Use .asOctets() method to retrieve data in pure octet-string form: >>> s = OctetString(hexValue='4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858') >>> s.prettyPrint() '0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858' >>> s.asOctets() "Operator XXXXXXXXXX : XXXXXXXXXX, XXXXXXX , Locally authenticated - successfully signed on to the terminal 'XXX.XXX.X.X@X' at 14:28 using 'XXXXXXXX XXX XXXXXXXX'.\nOperator Profiles: XXXXXXXXXXXXX" -ilya > On 09 Mar 2015, at 22:23, Tom Kr. <to...@we...> wrote: > > > Hi there, > > I'm new to this mailing list and I have a issue with the pysnmp / pyasn1 module. > I use python with version 3.4 and pysnmp with version 4.2.5. > The OS is Ubuntu server 14.04.2. > > # lsb_release -a > No LSB modules are available. > Distributor ID: Ubuntu > Description: Ubuntu 14.04.2 LTS > Release: 14.04 > Codename: trusty > > ii python-pysnmp4 4.2.5-1 all Python SNMP library for agents and managers (Python 2 module) > ii python-pyasn1 0.1.7-1ubuntu2 all ASN.1 library for Python (Python 2 module) > ii python3.4 3.4.0-2ubuntu1 amd64 Interactive high-level object-oriented language (version 3.4) > > I try to use the following script to read snmp traps and print this traps on the screen. > But unfortunately I have some troubles with multi-line traps. > This traps are only shown as hex values. > I think the problem is the decoder but I'm not very familiar with python and also not with pysnmp. > > I hope someone of you can help me or give me some ideas what I should do next. > For the moment I have no idea. > > The script: > ---------------------------------------------------------------------------------------------- > import sys,os > > sys.path.append('/usr/share/pyshared/') > > from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher > from pysnmp.carrier.asynsock.dgram import udp, udp6 > from pyasn1.codec.ber import decoder > from pysnmp.proto import api > > def trapCallback(transportDispatcher, transportDomain, transportAddress, wholeMsg): > while wholeMsg: > msgVer = int(api.decodeMessageVersion(wholeMsg)) > if msgVer in api.protoModules: > pMod = api.protoModules[msgVer] > else: > print('Unsupported SNMP version %s' % msgVer) > return > reqMsg, wholeMsg = decoder.decode( > wholeMsg, asn1Spec=pMod.Message(), > ) > print('Notification message from %s:%s: ' % ( > transportDomain, transportAddress > ) > ) > reqPDU = pMod.apiMessage.getPDU(reqMsg) > if reqPDU.isSameTypeWith(pMod.TrapPDU()): > if msgVer == api.protoVersion1: > print('Enterprise: %s' % ( > pMod.apiTrapPDU.getEnterprise(reqPDU).prettyPrint() > ) > ) > print('Agent Address: %s' % ( > pMod.apiTrapPDU.getAgentAddr(reqPDU).prettyPrint() > ) > ) > print('Generic Trap: %s' % ( > pMod.apiTrapPDU.getGenericTrap(reqPDU).prettyPrint() > ) > ) > print('Specific Trap: %s' % ( > pMod.apiTrapPDU.getSpecificTrap(reqPDU).prettyPrint() > ) > ) > print('Uptime: %s' % ( > pMod.apiTrapPDU.getTimeStamp(reqPDU).prettyPrint() > ) > ) > varBinds = pMod.apiTrapPDU.getVarBindList(reqPDU) > else: > varBinds = pMod.apiPDU.getVarBindList(reqPDU) > print('Var-binds:') > for oid, val in varBinds: > print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) > return wholeMsg > > transportDispatcher = AsynsockDispatcher() > > transportDispatcher.registerRecvCbFun(trapCallback) > > # UDP/IPv4 > transportDispatcher.registerTransport( > udp.domainName, udp.UdpSocketTransport().openServerMode(('localhost', 162)) > ) > > # UDP/IPv6 > transportDispatcher.registerTransport( > udp6.domainName, udp6.Udp6SocketTransport().openServerMode(('::1', 162)) > ) > > transportDispatcher.jobStarted(1) > > try: > # Dispatcher will never finish as job#1 never reaches zero > transportDispatcher.runDispatcher() > except: > transportDispatcher.closeDispatcher() > raise > ---------------------------------------------------------------------------------------------- > > > As you can see, the script is an example from the project side. > (http://pysnmp.sourceforge.net/examples/current/v1arch/manager/ntfrcv/v2c-multiple-transports.html <http://pysnmp.sourceforge.net/examples/current/v1arch/manager/ntfrcv/v2c-multiple-transports.html>) > > This is the part of the trap where the hex value is shown instead of the plain text. > string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 > > This is the message I would expect. > "Operator XXXXXXXXXX : XXXXXXXXXX, XXXXXXX , Locally authenticated - successfully signed on to the terminal 'XXX.XXX.X.X@X' at 14:28 <x-apple-data-detectors://4>using 'XXXXXXXX XXX XXXXXXXX'. > Operator Profiles: XXXXXXXXXXXXX" > > For me, the problem is located at the line feed. Is there a possibility to replace any line feed character with a space or nothing? > I think this should be done in the pyasn1 module, but I don't know how. > > Hope somebody can help me with my problem. > > Kind regards, > Tom > |
From: Tom Kr. <to...@we...> - 2015-03-09 19:23:12
|
Hi there, I'm new to this mailing list and I have a issue with the pysnmp / pyasn1 module. I use python with version 3.4 and pysnmp with version 4.2.5. The OS is Ubuntu server 14.04.2. # lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.2 LTS Release: 14.04 Codename: trusty ii python-pysnmp4 4.2.5-1 all Python SNMP library for agents and managers (Python 2 module) ii python-pyasn1 0.1.7-1ubuntu2 all ASN.1 library for Python (Python 2 module) ii python3.4 3.4.0-2ubuntu1 amd64 Interactive high-level object-oriented language (version 3.4) I try to use the following script to read snmp traps and print this traps on the screen. But unfortunately I have some troubles with multi-line traps. This traps are only shown as hex values. I think the problem is the decoder but I'm not very familiar with python and also not with pysnmp. I hope someone of you can help me or give me some ideas what I should do next. For the moment I have no idea. The script: ---------------------------------------------------------------------------------------------- import sys,os sys.path.append('/usr/share/pyshared/') from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher from pysnmp.carrier.asynsock.dgram import udp, udp6 from pyasn1.codec.ber import decoder from pysnmp.proto import api def trapCallback(transportDispatcher, transportDomain, transportAddress, wholeMsg): while wholeMsg: msgVer = int(api.decodeMessageVersion(wholeMsg)) if msgVer in api.protoModules: pMod = api.protoModules[msgVer] else: print('Unsupported SNMP version %s' % msgVer) return reqMsg, wholeMsg = decoder.decode( wholeMsg, asn1Spec=pMod.Message(), ) print('Notification message from %s:%s: ' % ( transportDomain, transportAddress ) ) reqPDU = pMod.apiMessage.getPDU(reqMsg) if reqPDU.isSameTypeWith(pMod.TrapPDU()): if msgVer == api.protoVersion1: print('Enterprise: %s' % ( pMod.apiTrapPDU.getEnterprise(reqPDU).prettyPrint() ) ) print('Agent Address: %s' % ( pMod.apiTrapPDU.getAgentAddr(reqPDU).prettyPrint() ) ) print('Generic Trap: %s' % ( pMod.apiTrapPDU.getGenericTrap(reqPDU).prettyPrint() ) ) print('Specific Trap: %s' % ( pMod.apiTrapPDU.getSpecificTrap(reqPDU).prettyPrint() ) ) print('Uptime: %s' % ( pMod.apiTrapPDU.getTimeStamp(reqPDU).prettyPrint() ) ) varBinds = pMod.apiTrapPDU.getVarBindList(reqPDU) else: varBinds = pMod.apiPDU.getVarBindList(reqPDU) print('Var-binds:') for oid, val in varBinds: print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) return wholeMsg transportDispatcher = AsynsockDispatcher() transportDispatcher.registerRecvCbFun(trapCallback) # UDP/IPv4 transportDispatcher.registerTransport( udp.domainName, udp.UdpSocketTransport().openServerMode(('localhost', 162)) ) # UDP/IPv6 transportDispatcher.registerTransport( udp6.domainName, udp6.Udp6SocketTransport().openServerMode(('::1', 162)) ) transportDispatcher.jobStarted(1) try: # Dispatcher will never finish as job#1 never reaches zero transportDispatcher.runDispatcher() except: transportDispatcher.closeDispatcher() raise ---------------------------------------------------------------------------------------------- As you can see, the script is an example from the project side. (http://pysnmp.sourceforge.net/examples/current/v1arch/manager/ntfrcv/v2c-multiple-transports.html) This is the part of the trap where the hex value is shown instead of the plain text. string=0x4f70657261746f722058585858585858585858203a20585858585858585858582c2058585858585858202c204c6f63616c6c792061757468656e74696361746564202d207375636365737366756c6c79207369676e6564206f6e20746f20746865207465726d696e616c20275858582e5858582e582e584058272061742031343a3238207573696e672027585858585858585820585858205858585858585858272e0a4f70657261746f722050726f66696c65733a2058585858585858585858585858 This is the message I would expect. "Operator XXXXXXXXXX : XXXXXXXXXX, XXXXXXX , Locally authenticated - successfully signed on to the terminal 'XXX.XXX.X.X@X' at 14:28using 'XXXXXXXX XXX XXXXXXXX'. Operator Profiles: XXXXXXXXXXXXX" For me, the problem is located at the line feed. Is there a possibility to replace any line feed character with a space or nothing? I think this should be done in the pyasn1 module, but I don't know how. Hope somebody can help me with my problem. Kind regards, Tom |
From: Carlson, K D. <K.C...@xe...> - 2015-02-20 20:30:11
|
That did the trick, python3.4 now sees the module. I had to install the python3-setuptool with get-apt and then used easy install3.4 to install pysnmp so that python3.4 could recognize it. Thank you, Dave From: Ilya Etingof [mailto:il...@gl...] Sent: Friday, February 20, 2015 2:37 PM To: Carlson, K David Cc: pys...@li... Subject: Re: [pysnmp-users] Can't get pysnmp to run under Python 3.4 Hi David, A traceback would help better understand what’s going on. To test the availability of the library for specific Python version you could try to import it into one Python or another: $ python3.4 >>> import pysnmp >>> ^D $ python2.7 >>> import pysnmp >>> ^D To install pysnmp for python 3.4 you should run pip3.4 or easy_install-3.4. -ilya On 20 Feb 2015, at 21:29, Carlson, K David <K.C...@xe...<mailto:K.C...@xe...>> wrote: Whenever I run the PySNMP sample code in an IDLE 3.4 window I get “ImportError: No module named ‘pysnmp’” I have successfully installed Python 3.4 with IDLE and the OS already had Python 2.7.6 installed, I installed pysnmp 4.2.5 with easy_install. If I run the sample code at a Python 2.7.6 prompt in a terminal window it runs fine, trying the same with 3.4 gives me “NameError: name ‘errorIndication’ is not defined” . My linux skills are weak and I would think that this is a path issue but I can’t find any documentation that points me in the right direction. Any help would be appreciated. Thanks, Dave |
From: Ilya E. <il...@gl...> - 2015-02-20 19:36:49
|
Hi David, A traceback would help better understand what’s going on. To test the availability of the library for specific Python version you could try to import it into one Python or another: $ python3.4 >>> import pysnmp >>> ^D $ python2.7 >>> import pysnmp >>> ^D To install pysnmp for python 3.4 you should run pip3.4 or easy_install-3.4. -ilya > On 20 Feb 2015, at 21:29, Carlson, K David <K.C...@xe...> wrote: > > Whenever I run the PySNMP sample code in an IDLE 3.4 window I get “ImportError: No module named ‘pysnmp’” > I have successfully installed Python 3.4 with IDLE and the OS already had Python 2.7.6 installed, I installed pysnmp 4.2.5 with easy_install. > If I run the sample code at a Python 2.7.6 prompt in a terminal window it runs fine, trying the same with 3.4 gives me “NameError: name ‘errorIndication’ is not defined” . > My linux skills are weak and I would think that this is a path issue but I can’t find any documentation that points me in the right direction. Any help would be appreciated. > > Thanks, > > Dave |
From: R. D. M. <rdm...@bi...> - 2015-02-20 19:35:30
|
On Fri, 20 Feb 2015 19:20:22 +0000, <Pau...@De...> wrote: > > > On Feb 20, 2015, at 1:59 PM, R. David Murray <rdm...@bi...> wrote: > > > > On Fri, 20 Feb 2015 18:29:29 +0000, "Carlson, K David" <K.C...@xe...> wrote: > >> Whenever I run the PySNMP sample code in an IDLE 3.4 window I get "ImportError: No module named 'pysnmp'" > >> I have successfully installed Python 3.4 with IDLE and the OS already had Python 2.7.6 installed, I installed pysnmp 4.2.5 with easy_install. > >> If I run the sample code at a Python 2.7.6 prompt in a terminal window it runs fine, trying the same with 3.4 gives me "NameError: name 'errorIndication' is not defined" . > >> My linux skills are weak and I would think that this is a path issue but I can't find any documentation that points me in the right direction. Any help would be appreciated. > > > > It sounds like you've installed pysnmp for 2.7.6, but *not* for 3.4. > > For 3.4, use 'pip install' instead of easy_install, it's easier (and > > built in, now). > > Donât you need to say âpip3 installâ? You are correct. I usually use virtual environments, so I forgot the '3' since in a venv I don't need to specify it. > The surprising property of Python library installs is that they go into a version-specific library path, so the Python version that runs the install script is the one that receives the resulting library. If you have two Pythons, you have to install twice, with the script running under each of the Pythons in turn. Yeah. There are good reasons for this, but it can indeed be surprising. --David |
From: <Pau...@De...> - 2015-02-20 19:20:37
|
> On Feb 20, 2015, at 1:59 PM, R. David Murray <rdm...@bi...> wrote: > > On Fri, 20 Feb 2015 18:29:29 +0000, "Carlson, K David" <K.C...@xe...> wrote: >> Whenever I run the PySNMP sample code in an IDLE 3.4 window I get "ImportError: No module named 'pysnmp'" >> I have successfully installed Python 3.4 with IDLE and the OS already had Python 2.7.6 installed, I installed pysnmp 4.2.5 with easy_install. >> If I run the sample code at a Python 2.7.6 prompt in a terminal window it runs fine, trying the same with 3.4 gives me "NameError: name 'errorIndication' is not defined" . >> My linux skills are weak and I would think that this is a path issue but I can't find any documentation that points me in the right direction. Any help would be appreciated. > > It sounds like you've installed pysnmp for 2.7.6, but *not* for 3.4. > For 3.4, use 'pip install' instead of easy_install, it's easier (and > built in, now). Don’t you need to say “pip3 install”? The surprising property of Python library installs is that they go into a version-specific library path, so the Python version that runs the install script is the one that receives the resulting library. If you have two Pythons, you have to install twice, with the script running under each of the Pythons in turn. paul |
From: R. D. M. <rdm...@bi...> - 2015-02-20 19:15:01
|
On Fri, 20 Feb 2015 18:29:29 +0000, "Carlson, K David" <K.C...@xe...> wrote: > Whenever I run the PySNMP sample code in an IDLE 3.4 window I get "ImportError: No module named 'pysnmp'" > I have successfully installed Python 3.4 with IDLE and the OS already had Python 2.7.6 installed, I installed pysnmp 4.2.5 with easy_install. > If I run the sample code at a Python 2.7.6 prompt in a terminal window it runs fine, trying the same with 3.4 gives me "NameError: name 'errorIndication' is not defined" . > My linux skills are weak and I would think that this is a path issue but I can't find any documentation that points me in the right direction. Any help would be appreciated. It sounds like you've installed pysnmp for 2.7.6, but *not* for 3.4. For 3.4, use 'pip install' instead of easy_install, it's easier (and built in, now). --David |
From: Carlson, K D. <K.C...@xe...> - 2015-02-20 18:41:55
|
Whenever I run the PySNMP sample code in an IDLE 3.4 window I get "ImportError: No module named 'pysnmp'" I have successfully installed Python 3.4 with IDLE and the OS already had Python 2.7.6 installed, I installed pysnmp 4.2.5 with easy_install. If I run the sample code at a Python 2.7.6 prompt in a terminal window it runs fine, trying the same with 3.4 gives me "NameError: name 'errorIndication' is not defined" . My linux skills are weak and I would think that this is a path issue but I can't find any documentation that points me in the right direction. Any help would be appreciated. Thanks, Dave |
From: Марат Р. <mar...@gm...> - 2015-02-19 11:16:33
|
Hello Ilya, You're right. It works fine with pysnmp 4.2.6. Thanks! Best regards, Marat Rysbekov 2015-02-19 16:40 GMT+06:00 Ilya Etingof <il...@gl...>: > Hello Marat, > > That’s likely a bug. Could you please try the latest pysnmp (which works > just fine to me with your code): > > https://sourceforge.net/projects/pysnmp/files/pysnmp/4.2.6/ > > and alert me in case of further issues? > > -ilya > > On 19 Feb 2015, at 12:51, Марат Рысбеков <mar...@gm...> > wrote: > > Hello, > > I would like to use pysnmp 4.2.5 (installed via pip) to send SNMP traps. I > tried running the following example (taken from > http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py > ): > > --- > from pysnmp.entity.rfc3413.oneliner import ntforg > > ntfOrg = ntforg.NotificationOriginator() > > errorIndication = ntfOrg.sendNotification( > ntforg.CommunityData('public'), > ntforg.UdpTransportTarget(('localhost', 162)), > 'trap', > ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), > ( ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name' ) > ) > > if errorIndication: > print('Notification not sent: %s' % errorIndication) > --- > > When I run it with Python 3.4.2 I get this: > > --- > Exception ignored in: <bound method AsynNotificationOriginator.__del__ of > <pysnmp.entity.rfc3413.oneliner.ntforg.AsynNotificationOriginator object at > 0x7fd0a07a4978>> > Traceback (most recent call last): > File > "/usr/local/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/ntforg.py", > line 33, in __del__ > def __del__(self): self.uncfgNtfOrg() > File > "/usr/local/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/ntforg.py", > line 100, in uncfgNtfOrg > for authDataKey in authDataKeys: > RuntimeError: dictionary changed size during iteration > --- > > With Python 2.7.8 the example works just fine. > > Is the example not applicable to pysnmp 4.2.5 / Python 3.4? > > Best regards, > Marat Rysbekov > > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk_______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users > > > |
From: Ilya E. <il...@gl...> - 2015-02-19 10:40:49
|
Hello Marat, That’s likely a bug. Could you please try the latest pysnmp (which works just fine to me with your code): https://sourceforge.net/projects/pysnmp/files/pysnmp/4.2.6/ and alert me in case of further issues? -ilya > On 19 Feb 2015, at 12:51, Марат Рысбеков <mar...@gm...> wrote: > > Hello, > > I would like to use pysnmp 4.2.5 (installed via pip) to send SNMP traps. I tried running the following example (taken from http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py <http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py>): > > --- > from pysnmp.entity.rfc3413.oneliner import ntforg > > ntfOrg = ntforg.NotificationOriginator() > > errorIndication = ntfOrg.sendNotification( > ntforg.CommunityData('public'), > ntforg.UdpTransportTarget(('localhost', 162)), > 'trap', > ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), > ( ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name' ) > ) > > if errorIndication: > print('Notification not sent: %s' % errorIndication) > --- > > When I run it with Python 3.4.2 I get this: > > --- > Exception ignored in: <bound method AsynNotificationOriginator.__del__ of <pysnmp.entity.rfc3413.oneliner.ntforg.AsynNotificationOriginator object at 0x7fd0a07a4978>> > Traceback (most recent call last): > File "/usr/local/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/ntforg.py", line 33, in __del__ > def __del__(self): self.uncfgNtfOrg() > File "/usr/local/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/ntforg.py", line 100, in uncfgNtfOrg > for authDataKey in authDataKeys: > RuntimeError: dictionary changed size during iteration > --- > > With Python 2.7.8 the example works just fine. > > Is the example not applicable to pysnmp 4.2.5 / Python 3.4? > > Best regards, > Marat Rysbekov > ------------------------------------------------------------------------------ > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server > from Actuate! Instantly Supercharge Your Business Reports and Dashboards > with Interactivity, Sharing, Native Excel Exports, App Integration & more > Get technology previously reserved for billion-dollar corporations, FREE > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk_______________________________________________ > pysnmp-users mailing list > pys...@li... > https://lists.sourceforge.net/lists/listinfo/pysnmp-users |
From: Марат Р. <mar...@gm...> - 2015-02-19 09:51:35
|
Hello, I would like to use pysnmp 4.2.5 (installed via pip) to send SNMP traps. I tried running the following example (taken from http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py ): --- from pysnmp.entity.rfc3413.oneliner import ntforg ntfOrg = ntforg.NotificationOriginator() errorIndication = ntfOrg.sendNotification( ntforg.CommunityData('public'), ntforg.UdpTransportTarget(('localhost', 162)), 'trap', ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), ( ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name' ) ) if errorIndication: print('Notification not sent: %s' % errorIndication) --- When I run it with Python 3.4.2 I get this: --- Exception ignored in: <bound method AsynNotificationOriginator.__del__ of <pysnmp.entity.rfc3413.oneliner.ntforg.AsynNotificationOriginator object at 0x7fd0a07a4978>> Traceback (most recent call last): File "/usr/local/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/ntforg.py", line 33, in __del__ def __del__(self): self.uncfgNtfOrg() File "/usr/local/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/ntforg.py", line 100, in uncfgNtfOrg for authDataKey in authDataKeys: RuntimeError: dictionary changed size during iteration --- With Python 2.7.8 the example works just fine. Is the example not applicable to pysnmp 4.2.5 / Python 3.4? Best regards, Marat Rysbekov |
From: Frédéric P. <fr...@fp...> - 2015-02-12 17:36:49
|
Code-wise, I have no issue, as the fix is already committed, and quick testing shows it's good. I think it's just a tagging release issue :) Le jeudi 12 à 17:49, Ilya Etingof a écrit : > Oh, that's a mess. :-( > > I just put up the latest CVS code on SF downloads. Let me know in > case of any issues. > > -ilya > > On 02/12/2015 07:19 PM, Frédéric Perrin wrote: >> Le jeudi 12 à 16:51, Frédéric Perrin a écrit : >>> Hi Ilya, >>> >>> What Debian calls 4.2.5 is actually 4.2.5rc2. >> I'm getting confused somewhere... The file listed on the SF.net download >> page as pysnmp-4.2.5.tar.gz contains a CHANGES file whose first line is >> "Revision 4.2.5rc2", and the commit I list further down is not part of >> it. >> >> The file you linked to identifies itself as 4.2.6rc0, and lists that >> commit under "Revision 4.2.5". >> >>> This means the Debian >>> version is missing the following commit: >>> >>> Mon Aug 18 07:21:17 2014 UTC (5 months, 3 weeks ago) by elie >>> >>> CommandGenerator.getNext() & .getBulk() methods now support the >>> maxCalls kwarg to limit the maximum number of request-response >>> iterations to perform >>> >>> http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py?r1=1.96&r2=1.97 >>> >>> (with this change, the size of varBindTotalTable is compared to maxRows >>> AFTER extending the table) >>> >>> Thanks Ilya, I think I need to take this with the Debian maintainer. >>> >>> Le jeudi 12 à 16:24, Ilya Etingof a écrit : >>>> Hi Frédéric, >>>> >>>> Just checked the latest (development) pysnmp operation: with maxRows=1 >>>> it sends just one GETNEXT: >>>> >>>> http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar >>>> >>>> ilya >>>> >>>> On 02/12/2015 06:14 PM, Frédéric Perrin wrote: >>>>> Hi list, >>>>> >>>>> It seems that nextCmd() always sends one request too many. IOW, with the >>>>> following: >>>>> >>>>>>>> print cmdgen.CommandGenerator().nextCmd( >>>>> ... cmdgen.CommunityData("public"), >>>>> ... cmdgen.UdpTransportTarget(("192.168.100.240", 161)), >>>>> ... "1.3.6.1.2.1.1.4.0", >>>>> ... lexicographicMode = True, >>>>> ... maxRows = 1) >>>>> (None, Integer('noError'), Integer(0), [[(ObjectName(1.3.6.1.2.1.1.5.0), >>>>> OctetString('dut-1'))]]) >>>>> >>>>> Wireshark shows two GETNEXT being sent (and responded to), even though >>>>> only the first response is returned to me. I was expecting only one >>>>> request to be sent, as per maxRows. >>>>> >>>>> Am I doing something wrong? Or is there an off-by-one somewhere in >>>>> pysnmp? >>>>> >>>>> I'm running with python-pysnmp4 4.2.5-1 on Debian Sid. >>>>> >>>>> Cheers, >>>>> > -- Fred |
From: Ilya E. <il...@gl...> - 2015-02-12 16:50:01
|
Oh, that's a mess. :-( I just put up the latest CVS code on SF downloads. Let me know in case of any issues. -ilya On 02/12/2015 07:19 PM, Frédéric Perrin wrote: > Le jeudi 12 à 16:51, Frédéric Perrin a écrit : >> Hi Ilya, >> >> What Debian calls 4.2.5 is actually 4.2.5rc2. > I'm getting confused somewhere... The file listed on the SF.net download > page as pysnmp-4.2.5.tar.gz contains a CHANGES file whose first line is > "Revision 4.2.5rc2", and the commit I list further down is not part of > it. > > The file you linked to identifies itself as 4.2.6rc0, and lists that > commit under "Revision 4.2.5". > >> This means the Debian >> version is missing the following commit: >> >> Mon Aug 18 07:21:17 2014 UTC (5 months, 3 weeks ago) by elie >> >> CommandGenerator.getNext() & .getBulk() methods now support the >> maxCalls kwarg to limit the maximum number of request-response >> iterations to perform >> >> http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py?r1=1.96&r2=1.97 >> >> (with this change, the size of varBindTotalTable is compared to maxRows >> AFTER extending the table) >> >> Thanks Ilya, I think I need to take this with the Debian maintainer. >> >> Le jeudi 12 à 16:24, Ilya Etingof a écrit : >>> Hi Frédéric, >>> >>> Just checked the latest (development) pysnmp operation: with maxRows=1 >>> it sends just one GETNEXT: >>> >>> http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar >>> >>> ilya >>> >>> On 02/12/2015 06:14 PM, Frédéric Perrin wrote: >>>> Hi list, >>>> >>>> It seems that nextCmd() always sends one request too many. IOW, with the >>>> following: >>>> >>>>>>> print cmdgen.CommandGenerator().nextCmd( >>>> ... cmdgen.CommunityData("public"), >>>> ... cmdgen.UdpTransportTarget(("192.168.100.240", 161)), >>>> ... "1.3.6.1.2.1.1.4.0", >>>> ... lexicographicMode = True, >>>> ... maxRows = 1) >>>> (None, Integer('noError'), Integer(0), [[(ObjectName(1.3.6.1.2.1.1.5.0), >>>> OctetString('dut-1'))]]) >>>> >>>> Wireshark shows two GETNEXT being sent (and responded to), even though >>>> only the first response is returned to me. I was expecting only one >>>> request to be sent, as per maxRows. >>>> >>>> Am I doing something wrong? Or is there an off-by-one somewhere in >>>> pysnmp? >>>> >>>> I'm running with python-pysnmp4 4.2.5-1 on Debian Sid. >>>> >>>> Cheers, >>>> |
From: Frédéric P. <fr...@fp...> - 2015-02-12 16:18:14
|
Le jeudi 12 à 16:51, Frédéric Perrin a écrit : > Hi Ilya, > > What Debian calls 4.2.5 is actually 4.2.5rc2. I'm getting confused somewhere... The file listed on the SF.net download page as pysnmp-4.2.5.tar.gz contains a CHANGES file whose first line is "Revision 4.2.5rc2", and the commit I list further down is not part of it. The file you linked to identifies itself as 4.2.6rc0, and lists that commit under "Revision 4.2.5". > This means the Debian > version is missing the following commit: > > Mon Aug 18 07:21:17 2014 UTC (5 months, 3 weeks ago) by elie > > CommandGenerator.getNext() & .getBulk() methods now support the > maxCalls kwarg to limit the maximum number of request-response > iterations to perform > > http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py?r1=1.96&r2=1.97 > > (with this change, the size of varBindTotalTable is compared to maxRows > AFTER extending the table) > > Thanks Ilya, I think I need to take this with the Debian maintainer. > > Le jeudi 12 à 16:24, Ilya Etingof a écrit : >> Hi Frédéric, >> >> Just checked the latest (development) pysnmp operation: with maxRows=1 >> it sends just one GETNEXT: >> >> http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar >> >> ilya >> >> On 02/12/2015 06:14 PM, Frédéric Perrin wrote: >>> Hi list, >>> >>> It seems that nextCmd() always sends one request too many. IOW, with the >>> following: >>> >>>>>> print cmdgen.CommandGenerator().nextCmd( >>> ... cmdgen.CommunityData("public"), >>> ... cmdgen.UdpTransportTarget(("192.168.100.240", 161)), >>> ... "1.3.6.1.2.1.1.4.0", >>> ... lexicographicMode = True, >>> ... maxRows = 1) >>> (None, Integer('noError'), Integer(0), [[(ObjectName(1.3.6.1.2.1.1.5.0), >>> OctetString('dut-1'))]]) >>> >>> Wireshark shows two GETNEXT being sent (and responded to), even though >>> only the first response is returned to me. I was expecting only one >>> request to be sent, as per maxRows. >>> >>> Am I doing something wrong? Or is there an off-by-one somewhere in >>> pysnmp? >>> >>> I'm running with python-pysnmp4 4.2.5-1 on Debian Sid. >>> >>> Cheers, >>> >> -- Fred |
From: Frédéric P. <fr...@fp...> - 2015-02-12 15:49:52
|
Hi Ilya, What Debian calls 4.2.5 is actually 4.2.5rc2. This means the Debian version is missing the following commit: Mon Aug 18 07:21:17 2014 UTC (5 months, 3 weeks ago) by elie CommandGenerator.getNext() & .getBulk() methods now support the maxCalls kwarg to limit the maximum number of request-response iterations to perform http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/pysnmp/entity/rfc3413/oneliner/cmdgen.py?r1=1.96&r2=1.97 (with this change, the size of varBindTotalTable is compared to maxRows AFTER extending the table) Thanks Ilya, I think I need to take this with the Debian maintainer. Le jeudi 12 à 16:24, Ilya Etingof a écrit : > Hi Frédéric, > > Just checked the latest (development) pysnmp operation: with maxRows=1 > it sends just one GETNEXT: > > http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar > > ilya > > On 02/12/2015 06:14 PM, Frédéric Perrin wrote: >> Hi list, >> >> It seems that nextCmd() always sends one request too many. IOW, with the >> following: >> >>>>> print cmdgen.CommandGenerator().nextCmd( >> ... cmdgen.CommunityData("public"), >> ... cmdgen.UdpTransportTarget(("192.168.100.240", 161)), >> ... "1.3.6.1.2.1.1.4.0", >> ... lexicographicMode = True, >> ... maxRows = 1) >> (None, Integer('noError'), Integer(0), [[(ObjectName(1.3.6.1.2.1.1.5.0), >> OctetString('dut-1'))]]) >> >> Wireshark shows two GETNEXT being sent (and responded to), even though >> only the first response is returned to me. I was expecting only one >> request to be sent, as per maxRows. >> >> Am I doing something wrong? Or is there an off-by-one somewhere in >> pysnmp? >> >> I'm running with python-pysnmp4 4.2.5-1 on Debian Sid. >> >> Cheers, >> > -- Fred |
From: Ilya E. <il...@gl...> - 2015-02-12 15:24:17
|
Hi Frédéric, Just checked the latest (development) pysnmp operation: with maxRows=1 it sends just one GETNEXT: http://pysnmp.cvs.sourceforge.net/viewvc/pysnmp/pysnmp/?view=tar ilya On 02/12/2015 06:14 PM, Frédéric Perrin wrote: > Hi list, > > It seems that nextCmd() always sends one request too many. IOW, with the > following: > >>>> print cmdgen.CommandGenerator().nextCmd( > ... cmdgen.CommunityData("public"), > ... cmdgen.UdpTransportTarget(("192.168.100.240", 161)), > ... "1.3.6.1.2.1.1.4.0", > ... lexicographicMode = True, > ... maxRows = 1) > (None, Integer('noError'), Integer(0), [[(ObjectName(1.3.6.1.2.1.1.5.0), > OctetString('dut-1'))]]) > > Wireshark shows two GETNEXT being sent (and responded to), even though > only the first response is returned to me. I was expecting only one > request to be sent, as per maxRows. > > Am I doing something wrong? Or is there an off-by-one somewhere in > pysnmp? > > I'm running with python-pysnmp4 4.2.5-1 on Debian Sid. > > Cheers, > |