etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
580 stars 200 forks source link

Issue walking an oid #147

Closed scramatte closed 6 years ago

scramatte commented 6 years ago

Hello,

I'm build a script to get statuses of docsis cable modem. Using the following OID 1.3.6.1.2.1.10.127.1.3.3.1.9 I'm able to pick data I need for my script.

My issue is when I achieved a walk with pysnmp and the script loop finish to read whole children of OID: 1.3.6.1.2.1.10.127.1.3.3.1.9 , pysnmp jump to OID: 1.3.6.1.2.1.10.127.1.3.3.1.10 instead of exit.

How can I keep snmp walking in the current scope Linux snmpwalk command line works as expected.

Regards

etingof commented 6 years ago

How exactly you do the walk? Can you share that part of your script?

If you are using the hlapi API, try flipping the lexicographicMode parameter to False.

scramatte commented 6 years ago
host = '172.16.0.2'
community = 'public'
port = 161
oid = '1.3.6.1.2.1.10.127.1.3.3.1.9'
for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd(SnmpEngine(),
    CommunityData(community),
    UdpTransportTarget((host, port)),
    ContextData(),
    ObjectType(ObjectIdentity(oid))):   
    if errorIndication:  # SNMP engine errors
        raise Exception(errorIndication)
    elif errorStatus:  # SNMP agent errors
            print('%s at %s' % (errorStatus.prettyPrint(), varBinds[int(errorIndex)-1] if errorIndex else '?'))
    else:
        for oid,value in varBinds:  # SNMP response contents
            print(oid)
            print(value)
scramatte commented 6 years ago

Sorry I'm newbie with Python! Can you told me how can I pass lexicographicMode option to nexCmd function?

etingof commented 6 years ago
...
nextCmd(SnmpEngine(),
    CommunityData(community),
    UdpTransportTarget((host, port)),
    ContextData(),
    ObjectType(ObjectIdentity(oid)),
        lexicographicMode=True):    
...