lextudio / sharpsnmplib

C# SNMP Library (#SNMP) - Open source SNMP implementation for C# and .NET
https://sharpsnmp.com
MIT License
357 stars 152 forks source link

Custom Mib Browser #374

Closed lextudio-support closed 3 weeks ago

lextudio-support commented 3 weeks ago

Hi,

I am trying to create a simple mib browser to parse mib files and update it in a tree view.

Can you please tell me the steps to parse a simple MIB file ( the standard RFC1213-MIB.mib) and get the list of data.

IEnumerable list = Lextm.SharpSnmpLib.Mib.Parser.Compile(openfiledialog.FileName);

Iam unable to access the data in the list as i see only MibModule is the class implementing IModule and it is an internal sealed class :(

Ive even tried looping through list.GetEnumerator().Current.Dependents, but it throws an object reference error!

Kindly Help!

Original Reported Date: 2010-04-27T23:02:43.117-07:00 Original CodePlex Discussion Thread ID: 210803

lextudio-support commented 3 weeks ago

Copied from CodePlex without authors:

Hi,

You can provide your own implementation of SharpSnmpLib.Mib.dll and then build your own browser on it.

If you use our implementation of SharpSnmpLib.Mib.dll, you have to use what is exposed by IModule.

Regards,

Lex

Original Posted Date: 2010-04-28T02:29:46.963-07:00

lextudio-support commented 3 weeks ago

Copied from CodePlex without authors:

Thanks Lex,

I guess i will share the source code here once i am done with the changes then. Just for other people like me to reference.

Also i find the documentation a bit not up to the mark. If you agree, i can help you with creating a CHM or PDF file for reference.

I am working on developing a tester for SNMP and your library i must say serves my purpose very well.

Great work!

Regards

Aditya

Original Posted Date: 2010-04-28T02:34:51.977-07:00

lextudio-support commented 3 weeks ago

Copied from CodePlex without authors:

Hi Aditya,

Actually if you have your own SharpSnmpLib.Mib implementation, and only reference SharpSnmpLib.dll, your implementation can be under any terms (open source or not). That fully depends on your decision, as LGPL does not force you to go open source. The only exception is that you make lots of usage on our LGPL based implementation.

Regarding the documentation, I am happy to receive any assistance you can provide. We need a lot of help in this area.

Regards,

Lex

Original Posted Date: 2010-04-28T04:09:48.107-07:00

lextudio-support commented 3 weeks ago

Copied from CodePlex without authors:

Hi Lex,

Actually i figured out the way to get MIB data from the existing library. I missed out earlier thanks to my dumbness with c# generics :P

Anyway here is the code to get MIB Data from an MIB file and populate on a treeview!

        OpenFileDialog openfiledialog = new OpenFileDialog();  
        openfiledialog.Filter = "MIB Files|*.mib";  
        openfiledialog.Title = "Select an MIB...";  

        if (openfiledialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)  
        {  

            IEnumerable<IModule> list = Parser.Compile(openfiledialog.FileName);  

            IEnumerator listEnumerator = list.GetEnumerator();  
            while (listEnumerator.MoveNext())  
            {  
                IModule moduleObj = (IModule)listEnumerator.Current;  
                //  
                TreeNode moduleNode = new TreeNode(moduleObj.Name);  
                mibTreeView.Nodes.Add(moduleNode);  
                //  
                IEnumerator depEnumerator = moduleObj.Dependents.GetEnumerator();  
                IEnumerator entityEnumerator = moduleObj.Entities.GetEnumerator();  
                IEnumerator objEnumerator = moduleObj.Objects.GetEnumerator();  
                while (depEnumerator.MoveNext())  
                {  
                    string dep = (string)depEnumerator.Current;  
                    TreeNode node = new TreeNode(dep);  
                    moduleNode.Nodes.Add(dep);  
                }  
                while (entityEnumerator.MoveNext())  
                {  
                    IEntity entityObj = (IEntity)entityEnumerator.Current;  
                    TreeNode node = new TreeNode(entityObj.Name);  
                    node.Nodes.Add(entityObj.ModuleName);  
                    node.Nodes.Add(entityObj.Parent);  
                    node.Nodes.Add(entityObj.Value.ToString());  
                    moduleNode.Nodes.Add(node);  

                }  
                while (objEnumerator.MoveNext())  
                {  
                    IEntity objObj = (IEntity)objEnumerator.Current;  
                    TreeNode node = new TreeNode(objObj.Name);  
                    node.Nodes.Add(objObj.ModuleName);  
                    node.Nodes.Add(objObj.Parent);  
                    node.Nodes.Add(objObj.Value.ToString());  
                    moduleNode.Nodes.Add(node);  
                }                      
            }  
        }

And lex, i would help you with the documentation. For starters i would add /// comments to every function i am able to understand, and probably generate a chm from them maybe using NDoc.

I would take time after my work hours to help you as much as i can.

Please tell me if i need to know anything more on documentation.

Regards,

ADITYA

Original Posted Date: 2010-04-28T05:05:17.19-07:00

lextudio-support commented 3 weeks ago

Copied from CodePlex without authors:

Hi Lex,

Sorry to bother u again!

Is it possible to get other details of OID objects like SYNTAX,ACCESS,STATUS,DESCRIPTION?

Can you please update with a raw code snippet on how to do that?

Thank you once again

Regards,

Aditya

Original Posted Date: 2010-04-28T23:29:43.92-07:00

lextudio-support commented 3 weeks ago

Copied from CodePlex without authors:

Our MIB parser does not yet extract such data from the documents. So at this moment, there is no way to do that.

Regards,

Lex

Original Posted Date: 2010-04-29T16:28:25.387-07:00

lextudio-support commented 3 weeks ago

Marked as Answer Date: 2013-10-06T21:34:36.48-07:00