[netsnmp 5.9] python module goes "Segmentation fault" with some (binary) OIDs ?

2021-02-01 Thread Diego Billi


I downloaded Net-nsmp 5.9 sources and installed the python module compiled for 
python3.

With some OID/MIBS my python program goes "Segmentation fault".

The same python code tested with python 2.7 works.

It think the problem raises when handling some binary values. 

In my test i just "walked" this MIBS:

walk on  1.3.6.1.2.1.3.1.1.1 -> ok
walk on  1.3.6.1.2.1.3.1.1.2 -> core dump
walk on  1.3.6.1.2.1.3.1.1.3 -> ok

The remote target host (server1) is running a SNMPD agent.

Where am i wrong? Thank you for your time.

Diego.





# The content of my target's MIB with shell commands (for comparison)


snmpwalk -v 1 -c public server1 1.3.6.1.2.1.3.1.1.1

iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.1 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.14 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.15 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.27 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.37 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.53 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.59 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.0.60 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.2.13 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.13.252 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.14.64 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.14.104 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.15.24 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.16.22 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.45 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.57 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.87 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.189 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.197 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.220 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.222 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.17.223 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.18.139 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.18.189 = INTEGER: 2
iso.3.6.1.2.1.3.1.1.1.2.1.1.1.18.191 = INTEGER: 2

snmpwalk -v 1 -c public server1 1.3.6.1.2.1.3.1.1.2

iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.1 = Hex-STRING: 32 39 56 FD 26 91 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.14 = Hex-STRING: 72 0B 91 1E BE FC 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.15 = Hex-STRING: 76 C0 5C C1 97 79 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.27 = Hex-STRING: 00 E0 81 2E 13 33 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.37 = Hex-STRING: 00 C0 FF 13 42 31 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.53 = Hex-STRING: 84 34 97 11 C4 74 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.59 = Hex-STRING: 00 0C 29 5E 84 36 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.0.60 = Hex-STRING: 06 F2 CC E5 D6 23 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.2.13 = Hex-STRING: 08 2E 5F D9 8C 40 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.13.252 = Hex-STRING: 00 15 65 16 42 58 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.14.64 = Hex-STRING: 00 15 65 16 3D FA 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.14.104 = Hex-STRING: 9C B6 D0 DB 90 19 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.15.24 = Hex-STRING: 00 13 19 C8 D1 7D 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.16.22 = Hex-STRING: BA 97 11 3F 90 54 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.45 = Hex-STRING: 00 15 65 16 42 8C 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.57 = Hex-STRING: 00 15 65 16 40 92 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.87 = Hex-STRING: AC 2B 6E A4 A8 FD 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.189 = Hex-STRING: AC E2 D3 D4 1A C3 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.197 = Hex-STRING: 7C B0 C2 96 7F 35 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.220 = Hex-STRING: 00 15 65 16 44 18 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.222 = Hex-STRING: 00 15 65 16 44 28 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.17.223 = Hex-STRING: 00 15 65 16 44 D4 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.18.139 = Hex-STRING: 84 EF 18 2E 7B 47 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.18.189 = Hex-STRING: 00 15 65 16 44 2A 
iso.3.6.1.2.1.3.1.1.2.2.1.1.1.18.191 = Hex-STRING: 00 15 65 16 3F 18 

snmpwalk -v 1 -c public server1 1.3.6.1.2.1.3.1.1.3

iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.1 = IpAddress: 1.1.0.1
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.14 = IpAddress: 1.1.0.14
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.15 = IpAddress: 1.1.0.15
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.27 = IpAddress: 1.1.0.27
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.37 = IpAddress: 1.1.0.37
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.53 = IpAddress: 1.1.0.53
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.59 = IpAddress: 1.1.0.59
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.0.60 = IpAddress: 1.1.0.60
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.2.13 = IpAddress: 1.1.2.13
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.13.252 = IpAddress: 1.1.13.252
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.14.64 = IpAddress: 1.1.14.64
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.14.104 = IpAddress: 1.1.14.104
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.15.24 = IpAddress: 1.1.15.24
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.16.22 = IpAddress: 1.1.16.22
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.17.45 = IpAddress: 1.1.17.45
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.17.57 = IpAddress: 1.1.17.57
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.17.87 = IpAddress: 1.1.17.87
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.17.89 = IpAddress: 1.1.17.89
iso.3.6.1.2.1.3.1.1.3.2.1.1.1.17.189 = IpAddress: 1.1.17.189
iso.3.6.1.2.

Re: Are python bindings thread safe?

2010-10-28 Thread Diego Billi
There is no bug notification on the bug track yet.

Kevin Miles ha scritto:
> Thanks. Sounds like the intention is that it's thread-safe but you found 
> a bug.
> 
> Can you recall the Bug ID? I can't find anything that matches your 
> description.
> 
> Kevin.
> ------
> From: "Diego Billi" 
> Sent: Thursday, October 28, 2010 10:14 AM
> To: "Kevin Miles" 
> Cc: 
> Subject: Re: Are python bindings thread safe?
> 
>> Kevin Miles ha scritto:
>>> Are the python bindings for net-snmp thread safe, for versions 1 & 2c?
>>
>> I'm using python binding inside a H24 multi-threaded application (>200 
>> threads)
>> and everything is working fine. I'm using version 1 and 2c.
>> I tested SNMP version 3 too, but not so deeply.
>>
>> So, YES, in theory.
>>
>> Practically speaking, there are few points inside the bindings code
>> where low level error handling is
>> still performed with not-threadsafe API (i notified the problem, but
>> nobody correted the code, mah!).
>>
>> Sometimes when the application is performing a snmp walk and receives 
>> SIGTERM, SIGINTR,
>> or other signals (which could interrupt a system call), it could crash
>> with a core dump.
>>
>> Up to now, i fixed with an auto-respawn solution.
>>
>> This is my exerience.
>>
>>
>>>
>>> My guess would be "yes", but the README for the bindings doesn't say 
>>> either way. The net-snmp FAQ gives guidelines for using the library 
>>> in a thread-safe way, but nowhere can I find an indication of whether 
>>> the python bindings adhere to these guidelines.
>>>
>>> Apologies if this is this has been asked before - the archive Search 
>>> facility gives me a 403 at the moment.
>>>
>>> Thanks,
>>> Kevin. 
>>> --
>>>  
>>>
>>> Nokia and AT&T present the 2010 Calling All Innovators-North America 
>>> contest
>>> Create new apps & games for the Nokia N8 for consumers in  U.S. and 
>>> Canada
>>> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in 
>>> marketing
>>> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi 
>>> Store http://p.sf.net/sfu/nokia-dev2dev
>>> ___
>>> Net-snmp-users mailing list
>>> Net-snmp-users@lists.sourceforge.net
>>> Please see the following page to unsubscribe or change other options:
>>> https://lists.sourceforge.net/lists/listinfo/net-snmp-users
>>
>>
> 


--
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
___
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users


Re: Are python bindings thread safe?

2010-10-28 Thread Diego Billi
Kevin Miles ha scritto:
> Are the python bindings for net-snmp thread safe, for versions 1 & 2c?

I'm using python binding inside a H24 multi-threaded application (>200 threads)
and everything is working fine. I'm using version 1 and 2c.
I tested SNMP version 3 too, but not so deeply.

So, YES, in theory.

Practically speaking, there are few points inside the bindings code
where low level error handling is
still performed with not-threadsafe API (i notified the problem, but
nobody correted the code, mah!).

Sometimes when the application is performing a snmp walk and receives SIGTERM, 
SIGINTR,
or other signals (which could interrupt a system call), it could crash
with a core dump.

Up to now, i fixed with an auto-respawn solution.

This is my exerience.


> 
> My guess would be "yes", but the README for the bindings doesn't say either 
> way. The net-snmp FAQ gives guidelines for using the library in a 
> thread-safe way, but nowhere can I find an indication of whether the python 
> bindings adhere to these guidelines.
> 
> Apologies if this is this has been asked before - the archive Search 
> facility gives me a 403 at the moment.
> 
> Thanks,
> Kevin. 
> 
> 
> 
> --
> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
> Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
> http://p.sf.net/sfu/nokia-dev2dev
> ___
> Net-snmp-users mailing list
> Net-snmp-users@lists.sourceforge.net
> Please see the following page to unsubscribe or change other options:
> https://lists.sourceforge.net/lists/listinfo/net-snmp-users


--
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
___
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users


[Python bindings] [ <= 5.5.pre2 ] malformed Varbind returned by sess.walk()

2009-05-19 Thread Diego Billi

NET-SNMP version: 5.5.pre2  (and 5.4.2.1 i think)

I'm using the NET-SNMP python bindings to perform a walk on the OID 
'1.3.6.1.2.1.25.3.3.1.2'.

I'm in a multi-thread environment. The thread doing the walk is not the 
main thread.
It's one of several thread of a thread-pool object.

All works fine, but *SOMETIMES* (not very often) the walk returns a strange
result. The input parameter VarList contains a set of "malformed" Varbind
objects. Some fields are None!

You can see the same output in two different tentatives (OUTPUT 1 and 
OUTPUT 2):

I don't know if it's a problem of my multi-threading environment or not.
I have problems in reproducing the bug.

Thank you.





SOURCE CODE
---

def __my_snmpwalk(*args, **kargs):

""" Just a modified version of netsnmp.snmpget """

sess = netsnmp.Session(**kargs)
if not sess.sess_ptr:
raise SnmpWrapperInvalidHost("Unable to open snmp session with: 
%s" % kargs['DestHost'])

if isinstance(args[0], netsnmp.client.VarList):
var_list = args[0]
else:
var_list = netsnmp.VarList()

for arg in args:
if isinstance(arg, netsnmp.client.Varbind):
var_list.append(arg)
else:
var_list.append(netsnmp.Varbind(arg))

res = sess.walk(var_list)

return res


def varstr(vl):
""" strings a VarList object """

s = ''
sep=''
for v in vl:
s += sep + str( (v.tag, str(v.iid), v.val) )
sep = ','
return s


def __do_walk(oid, host, port, community, timeout, retries,**options):
res = None

options['DestHost']   = host
options['RemotePort'] = port
options['Community']  = community
options['Timeout']= int(timeout * SNMP_ONE_SECOND)
options['Retries']= retries

if not options.has_key('Version'):
options['Version'] = SNMP_DEFAULT_VERSION

options['UseNumeric'] = 1# don not translate oids in return values!

# netsnmp wants fully qualified, dotted-decimal, numeric OID
if oid[0].isdigit():
oid2 = '.' + oid
else:
oid2 = oid

varlist = netsnmp.VarList( netsnmp.Varbind(oid2)  )

values = __my_snmpwalk(varlist, **options)


print "_do_walk() = ("
print "%s [len=%s]" % (varstr(varlist), len(varlist))
print ","
print "%s [len=%s]" % (values, len(values))
print ")"

return (varlist, values)


OUTPUT 1


_do_walk() = (
(None, 'None', '1') [len=1]
,
('1',) [len=1]
)


OUTPUT 2


_do_walk() = (
('.1.3.6.1.2.1.25.3.3.1.2', '768', '1') [len=1]
,
('1',) [len=1]
)


SNMPWALK COMMAND TEST
-

This is what i get with the command line program:

$ snmpwalk -On -v 1 -c public $HOST  1.3.6.1.2.1.25.3.3.1.2

.1.3.6.1.2.1.25.3.3.1.2.768 = INTEGER: 1


--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
___
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users


Problems with multi-threading and SNMP walk requests

2009-05-05 Thread Diego Billi

I want to create a thread which performs an SNMP walk, but the main thread
blocks on the pending request too.

I attach the source code of the test i wrote.

The main thread prints on standard output every second.
A second thread performs a walk.
The main threads blocks until the snmp walk is finished

Is it a bug?

How can avoid this problem? Is this a problem of the python bindings or 
what else?

Thank you very much.


TRY
===

$ python netsnmp_thread.py1.3.6.1.2.1.1.1



SOURCE CODE
==


import time,sys
import netsnmp
import threading


if len(sys.argv) != 3:
print "Usage: python %s  " % (sys.argv[0])
sys.exit(-1)
   
host = sys.argv[1]
   
oid_table  = sys.argv[2]

TIMEOUT=100
RETRIES=10


class TestThread(threading.Thread):
   
def __init__(self, oid):
super(TestThread, self).__init__()   
self.oid = oid
   
def run(self):
print "THREAD: start"
   
start = time.time()
var = netsnmp.Varbind( '.' + self.oid )
varlist = netsnmp.VarList( var )
t = netsnmp.snmpwalk( varlist , Version=1, DestHost=host,
  Community='public', 
Version=2,   
  UseNumeric=1,
  Timeout=TIMEOUT, Retries=RETRIES)
   
end = time.time()
   
print "THREAD: request time %s" % (end-start)
if t != None:
for a in varlist:
print '%s.%s = %s (%s, %s)' % (a.tag, str(a.iid), 
str(a.val), str(a.type), type(a.val))
else:
print "no result"
print "THREAD: finish!"


t = TestThread(oid_table)

last = time.time()
print "main thread..."

t.start()

while True:
now = time.time()
print "main thread going idle...elapsed=%s" % (now-last)
last = now
time.sleep(1.0)


--
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
___
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users


Problems with multi-threading and SNMP walk requests

2009-05-05 Thread Diego Billi

I want to create a thread which performs an SNMP walk, but the main thread
blocks on the pending request too.

I attach the source code of the test i wrote.

The main thread prints on standard output every second.
A second thread performs a walk.
The main threads blocks until the snmp walk is finished

Is it a bug?

How can avoid this problem? Is this a problem of the python bindings or 
what else?

Thank you very much.


TRY
===

$ python netsnmp_thread.py1.3.6.1.2.1.1.1



SOURCE CODE
==


import time,sys
import netsnmp
import threading


if len(sys.argv) != 3:
   print "Usage: python %s  " % (sys.argv[0])
   sys.exit(-1)
  host = sys.argv[1]
  oid_table  = sys.argv[2]

TIMEOUT=100
RETRIES=10


class TestThread(threading.Thread):
 def __init__(self, oid):
   super(TestThread, self).__init__()  self.oid = oid
 def run(self):
   print "THREAD: start"
 start = time.time()
   var = netsnmp.Varbind( '.' + self.oid )
   varlist = netsnmp.VarList( var )
   t = netsnmp.snmpwalk( varlist , Version=1, DestHost=host,
 Community='public', 
Version=2,   
 UseNumeric=1,
 Timeout=TIMEOUT, Retries=RETRIES)
 end = time.time()
 print "THREAD: request time %s" % (end-start)
   if t != None:
   for a in varlist:
   print '%s.%s = %s (%s, %s)' % (a.tag, str(a.iid), 
str(a.val), str(a.type), type(a.val))
   else:
   print "no result"
   print "THREAD: finish!"


t = TestThread(oid_table)

last = time.time()
print "main thread..."

t.start()

while True:
   now = time.time()
   print "main thread going idle...elapsed=%s" % (now-last)
   last = now
   time.sleep(1.0)

--
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
___
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users