Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexicographicMode seems to behave in an opposite manner. #49

Closed
thejpanganiban opened this issue Mar 26, 2017 · 2 comments
Closed

lexicographicMode seems to behave in an opposite manner. #49

thejpanganiban opened this issue Mar 26, 2017 · 2 comments

Comments

@thejpanganiban
Copy link

Excellent work on the project!

Was trying to retrieve all variables per MIB and realized that running nextCmd with the option lexicographicMode unset (defaults to True according to the docs) yields beyond the scope of the MIB. Tried to explicitly set it to False and now it does not go beyond the scope of the MIB.

from pysnmp import hlapi as snmp

iterator = snmp.nextCmd(
    snmp.SnmpEngine(),
    snmp.CommunityData('public'),
    snmp.UdpTransportTarget(('192.168.1.11', 161)),
    snmp.ContextData(),
    snmp.ObjectType(snmp.ObjectIdentity('IF-MIB')),
    lexicographicMode=False,  # After setting this to False, it now seems return only the IF-MIB OIDs.
)

for errorIndication, errorStatus, errorIndex, varBinds in iterator:
    if errorIndication:
        print(errorIndication)
    elif errorStatus:
        print('%s at %s' % (errorStatus.prettyPrint(),
            errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
    else:
        print('=' * 80)
        for varBind in varBinds:
            print(' = '.join([x.prettyPrint() for x in varBind]))

Or was I missing something?


I'm running on:
python:3.6 (docker)
pysnmp==4.3.5
pysmi==0.1.0
pysnmp-mibs==0.1.6

@etingof
Copy link
Owner

etingof commented Mar 27, 2017

Thank you for your report!

I think the documentation was confusing in regards to lexicographicMode option. I've just reworded it what would hopefully explains the behavior you observe.

In short -- "lexicographicMode = True" walks the MIB till the very end, otherwise walk is capped by the initial OIDs (serve as prefixes). You can change those prefixes at any time by feeding the new ones back into running generator (via its .send() method).

@etingof etingof closed this as completed Apr 9, 2017
@thejpanganiban
Copy link
Author

Thanks! That clears things up. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants