cederberg / mibble

Mibble is an open-source SNMP MIB parser library for Java.
https://www.mibble.org/
Other
113 stars 68 forks source link

symbolvaluemap in Mib.java has keys in the format like "referencetovalue.2" instead of full oid string like ".1.3.6.1.2.3.4" #9

Closed addictedanshul closed 11 years ago

addictedanshul commented 11 years ago

symbolvaluemap in Mib.java has keys in the format like "referencetovalue.2" instead of full oid string like ".1.3.6.1.2.3.4"

Full oid string is universal accepted key which should be used to search for mibvaluesymbol from the map.

cederberg commented 11 years ago

Have a look at Mib.getSymbolByOid(String oid). Think it does what you want, albeit only within the context of a single MIB file.

Also check MibLoader.getRootOid() and the accessor ObjectIdentifierValue.getChildByValue(int) to enable walking through the OID tree of all MIBs currently loaded.

I'll keep this issue open in order to document this better.

cederberg commented 11 years ago

BTW. The real issue here is that the OID keys contain "referencetovalue". This means that a MIB symbol wasn't properly resolved to a value (couldn't find the parent OID). Are you seeing any warnings or errors?

addictedanshul commented 11 years ago

Thanks for prompt reply

But I dont think there was any issue with the MIB loading.

It could find the parent easily... but when i saw the place where it populates the map...

symbolValueMap.put(value.getValue().toString(), symbol);

it is just putting the "value" as the key, which will always be in format "referencetovalue.3"

What I did is... convert that value to "ObjectIdentifierValue" and use "todetailstring" method.....

ObjectIdentifierValue root = (ObjectIdentifierValue) value.getValue();
symbolValueMapCustom.put("."+root.toDetailStringCustom(), symbol);

I had to edit that "todetailstring" method as well by commenting out below lines

// buffer.append(name); // buffer.append("("); buffer.append(value); // buffer.append(")");

Are you sure that key of the "symbolValueMap" should be full oid if the mib loading happens properly...

cederberg commented 11 years ago

Ok... Then the problem is rather in ObjectIdentifierValue.toString():

    public String toString() {
        StringBuffer buffer;

        if (cachedNumericValue == null) {
            buffer = new StringBuffer();
            if (parent != null) {
                buffer.append(parent.toString());
                buffer.append(".");
            }
            buffer.append(value);
            cachedNumericValue = buffer.toString();
        }
        return cachedNumericValue;
    }

I guess that the cachedNumericValue value is set too early, before the parent OID symbol has been resolved properly. Have to look into this.

Also, note that the correct functioning of Mibble would not include the leading . in the OID search, so you might want to adjust for that.

addictedanshul commented 11 years ago

Hi

If we purchase the commercial license, would you provide a new jar after incorporating the changes as required by us... Is the product supported for lifetime with commercial license, otherwise what is the duration...

We just need small tweaks as per our requirement...

cederberg commented 11 years ago

Sure, no problem. Contact me directly on sales@percederberg.net to discuss further.

addictedanshul commented 11 years ago

Hi

The technical team here has a concern that whether you would just make the changes and provide a new jar for us... Or would you GA (General Availability) it and include it in your stable releases, so that our purchased version doesn't conflict with your later updated release...

Our is a small requirement where we want

  1. fulloid string as key in the symbolvaluemap in Mib.java...
  2. and another map inside MibLoader.java which has mib name as key and mib object as value.
cederberg commented 11 years ago

Bug fixes (like this seems to be) will always end up in the public version. Features that are useful for the library are also generally included, unless the customer would object to that.

The requirements you mention seem very reasonable. I'd might build #2 slightly differently, but the functionality would be the same.

addictedanshul commented 11 years ago

Hi Cederberg

My bad, I checked again and found out that fulloid string is set as the key for the symbolvaluemap... The issue was wit the mib loading only...

I had one concern though, why symbolnamemap was not populated in "validate" method of Mib.java along with symbolvaluemap...

Also symbolvaluemap is private, there should be a getter for the same, so that using the same we can create our own maps...

I had to make a getter method for symbolvaluemap, and then using that map i had populated my own symbolnamemap

So basically we need two things...

  1. symbolNameMap should alsobe populated in the validate method
  2. and another map inside MibLoader.java which has mib name as key and mib object as value

Thanks Anshul

cederberg commented 11 years ago

Uploaded development version 2.10.alpha1 which adds MibLoader.getMibs(), fixes potential ObjectIdentifierValue.toString() issues and moves the API to Java 6.

http://www.mibble.org/download/development/index.html

addictedanshul commented 11 years ago

Hi Cederberg

One question...

If I have a mibvaluesymbol like below


XYZ OBJECT-TYPE SYNTAX ABC DESCRIPTION "Something"

::= { XYZ 2 }

now i want SYNTAX of "XYZ" output -> "ABC"

ABC itself is mibvaluesymbol like below


ABC ::= TEXTUAL-CONVENTION STATUS current DESCRIPTION "Something"

SYNTAX Integer32 (0..2147483647)

When I do

MibType mibType = mibValSym.getType();
SnmpObjectType snmpObjType = (SnmpObjectType)mibType; MibType newMibType = snmpObjType.getSyntax();

System.out.println("Syntax: "+newMibType.getName());

It returns me INTEGER and not ABC....

Please tell me, how can I get syntax of mibvaluesymbol when the syntax itself is another mibvaluesymbol...

Thanks Anshul

cederberg commented 11 years ago

Try mibType.getReferenceSymbol().getName() instead.

addictedanshul commented 11 years ago

I have done by using below:

MibTypeSymbol mibTypeSym = newMibType.getReferenceSymbol();

if(mibTypeSym != null) {
type = mibTypeSym.getName(); } else { type = newMibType.getName(); }

let me know, if there's an easy way out...

addictedanshul commented 11 years ago

Yes I have also used the same... Just that I have to check if referencesymbol comes up as null... then it has to be taken from mibtypename.

Thanks

addictedanshul commented 11 years ago

Hi Cederberg

While loading a MIB I get an error saying "unexpected token "-", expected "END""

Error is on below line in MIB, which is just a comment...

Some Mib value symbols .... .... .... ----------------------------- Entities for Disaster Recovery Module -------------------------------- (Error Line)

Can you please tell me the cause of this...

Thanks

cederberg commented 11 years ago

Its probably not a valid comment in ASN.1 syntax. Here are two valid examples:

... -- comment to the end of line
... -- comment start and end -- ...
addictedanshul commented 11 years ago

Will Mibble not work if the Mib file name and Mib name are different... Like "ABC.txt" has MIB name defined as "XYZ" inside

And will the Mibble load more than one MIB definitions in the MIB file... Rite now, it says MIB Loaded as null when it has different MIB name in the file or more than one MIB definitions...

addictedanshul commented 11 years ago

I am not able to debug the issue, as PARSER source code which is part of Grammatica is not available...

cederberg commented 11 years ago

Try the built-in MibblePrinter utility. It shows the data parsed by Mibble. Dig though the source code for MibWriter to find out how it works.

But basically, Mibble parses all MIBs in a MIB file but only returns the first one.

addictedanshul commented 11 years ago

Cederberg

Is the Mibble source java 7 compatible... because I could see some runtime errors as shown below... If not, can you please release a version which is java 7 compatible...

Duplicate local variable state Type mismatch: cannot convert from boolean to TokenStringDFA.State Syntax error on tokens, they can be merged to form == Duplicate local variable state The constructor TokenStringDFA.TransitionTree(TokenStringDFA) is undefined The constructor TokenStringDFA.TransitionTree(TokenStringDFA) is undefined The constructor TokenStringDFA.TransitionTree(TokenStringDFA) is undefined

at net.percederberg.grammatica.parser.TokenStringDFA$State.<init>(TokenStringDFA.java:26)
at net.percederberg.grammatica.parser.TokenStringDFA.<init>(TokenStringDFA.java:14)
at net.percederberg.grammatica.parser.Tokenizer$StringDFAMatcher.<init>(Tokenizer.java:309)
at net.percederberg.grammatica.parser.Tokenizer.<init>(Tokenizer.java:14)
at net.percederberg.mibble.asn1.Asn1Tokenizer.<init>(Asn1Tokenizer.java:49)
at net.percederberg.mibble.asn1.Asn1Parser.newTokenizer(Asn1Parser.java:120)
at net.percederberg.grammatica.parser.Parser.<init>(Parser.java:32)
at net.percederberg.grammatica.parser.RecursiveDescentParser.<init>(RecursiveDescentParser.java:19)
at net.percederberg.mibble.asn1.Asn1Parser.<init>(Asn1Parser.java:102)
at net.percederberg.mibble.MibLoader$MibSource.parseMib(MibLoader.java:983)
at net.percederberg.mibble.MibLoader.loadQueue(MibLoader.java:726)
at net.percederberg.mibble.MibLoader.load(MibLoader.java:552)
at net.percederberg.mibble.MibLoader.load(MibLoader.java:481)
addictedanshul commented 11 years ago

Please ignore... its working fine...