lextudio/sharpsnmplib

ObjectIdentifier.IsChildOf()

darrenstarr opened this issue · 4 comments

It would be amazing to get a new feature in ObjectIdentifier which would allow finding whether something is a child of something else.

var a = new ObjectIdentifier("1.3.6.1.4.1.9.9.23.1.1.1");
var b = new ObjectIdentifier("1.3.6.1.4.1.9.9.23.1.1.1.2.4");
if(b.IsChildOf(a))
{
    // Do something cool
}
lextm commented

You can implement your own. One of the ways is "1.3.6.1.4.1.9.9.23.1.1.1.2.4".StartsWith("1.3.6.1.4.1.9.9.23.1.1.1" + ".").

I have done this already using extension methods... but I imagine that most users of the library are probably all implementing the same functions. So, I was hoping for maybe IsChildOf() and IsRootOf() as I'd imagine they are the two most commonly rewritten extensions. I could make a pull request, if that is interesting to you.

lextm commented

I don't believe IsChildOf is a useful function for the users of this library. For example, this library itself only has a single place to do similar things,

https://github.com/lextudio/sharpsnmplib/blob/11.2.0/SharpSnmpLib/Messaging/Messenger.cs#L204

It is more useful for MIB document related operations, but that's covered by #SNMP Pro.

As I've said, I've implemented my own extensions, so whether you choose to do this is entirely up to you. But before you decide, let me offer an alternative use case for your library which maybe you haven't considered.

We decided to use your library rather than writing our own because we're doing network automation with Cisco devices. Cisco has MANY SNMP MIBs (such as CISCO-CONFIG-COPY-MIB) that identify sessions for initiating file transfers by appending an additional value to the end of each OID for the purpose of grouping. When walking the status of the nodes, to identify whether the resulting variable correlates to a specific operation to identify transfer completion, a simple compare isn't good enough and instead it's necessary to test whether the node is the child of a given OID within the MIB.

So while I truly appreciate your SNMP Pro tooling (which is quite beautiful), it is meant for management rather than automation and while using an extension is more than good enough for my needs, I still believe a unit tested common function as part of ObjectIdentifier would be logical in these cases. :)

Thanks for all the great work though!

Please feel free to close this if you still believe this is not right for your library.