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

Reply via email to