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

Ignore NoSuchInstance in Session._check_exception (multiple OIDs get()) #52

Closed
urban-1 opened this issue Mar 8, 2016 · 3 comments
Closed

Comments

@urban-1
Copy link

urban-1 commented Mar 8, 2016

Hi all,

This is a feature request to optionally ignore NoSuchInstance in Session._check_exception when more than one oids are queried via get(*oids). Minor changes are also needed in Session._convert to be able to handle this.

Why??

I am using the Session directly and I have been told that this is not the way snimpy is designed... so feel free to close this as invalid - I just thought I 'd ask...

What I need to do is query all the metrics of specific interface (I know the ifIndex) without fetching the whole ifTable. I am constructing all the OIDs and passing them directly to Session.get()

The problem is that different vendors support different OIDs! or they sometimes think is a good idea to randomly skip some... This causes get() to raise an exception while checking pysnmp's errorIndication.

Workaround

At the moment I am replacing the methods _check_exception and _convert. On the first I only remove the check for NoSuchInstance and on the second I add 2 lines:

   ...
            if isinstance(value, cl):
                return fn(value)

            # ... check for no instance ...
            if isinstance(value, rfc1905.NoSuchInstance):
                return "NoSuchInstance"

        # back to the original code    
        self._check_exception(value)

The output for a Cisco I test here:

ifOutErrors              : 0
ifAdminStatus            : 1
ifInOctets               : 0
ifInDiscards             : 0
ifOutDiscards            : 0
ifInUnknownProtos        : 0
ifDescr                  : b'Vlan500'
ifSpeed                  : 1000000000
ifOutNUcastPkts          : NoSuchInstance
ifMtu                    : 1998
ifInUcastPkts            : 0
ifLastChange             : 15925
ifInNUcastPkts           : NoSuchInstance
ifSpecific               : NoSuchInstance
ifType                   : 53
ifOutUcastPkts           : 65
ifOutQLen                : NoSuchInstance
ifOutOctets              : 4160
ifOperStatus             : 1
ifIndex                  : 500
ifPhysAddress            : b'blah'
ifInErrors               : 0

I think that would be a nice feature to have (disabled by default) that we can enable via Session.set_relax_no_instance(True) or something similar.

Please let me know if there an easier/other way of doing the same query with snimpy without working directly with pysnmp (I really like your Session :) ) and sorry for abusing snimpy again...

Andreas

@urban-1 urban-1 changed the title Ignore NoSuchInstance in Session._check_exception Ignore NoSuchInstance in Session._check_exception (multiple OIDs get()) Mar 8, 2016
@vincentbernat
Copy link
Owner

When using the high-level API, you can create a manager with none=True to get the behaviour you expect. Of course, this is of no use for you as you want to GET several OID at once.

We can add a similar argument to the Session it's tiny enough to not bother me that much.

@vincentbernat
Copy link
Owner

I didn't implement that for SNMPv1 as I would need to investigate a bit to see what it means about the global error message we get in this version.

@urban-1
Copy link
Author

urban-1 commented Mar 8, 2016

Amazingly fast response thanks a lot!!!

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