Introduction to Mibble

Mibble is an open-source SNMP (Simple Network Managment Protocol) MIB (Manageable Information Base) parser library for Java. It reads MIB files (in ASN.1 syntax) and provides an API to access all the information, including OIDs, types, descriptions, comments and the original MIB source text.

This document assumes that you are familiar with some common concepts in SNMP. If you are not, you can find more information about SNMP in RFC 3411 - An Architecture for Describing SNMP Management Frameworks or elsewhere on the web.

Running Utilities

Mibble is a library, and as such it contains no main application. Instead, it is supposed to be used by application writers to add support for reading MIB files to their respective applications. There are, however, a few small utilities available for testing the library — a pretty-printer, a validator and a MIB browser.

Information about how to run these programs can be found in the installation instructions in the release documentation. The output from the pretty-printer may not be very pretty, but it allows much easier scripting support than the original MIB syntax. For instance, it would be possible to create a shell script that extracts the full object identifiers from the pretty-printer output.

Below is the pretty-printer output for a part of the UDP-MIB file. Note the complete object identifiers present for each value:

VALUE udpMIB MODULE-IDENTITY (
  Last Updated: 9411010000Z
  Organization: IETF SNMPv2 Working Group
  Contact Info:         Keith McCloghrie

             Postal: Cisco Systems, Inc.
                     170 West Tasman Drive
                     San Jose, CA  95134-1706
                     US

             Phone:  +1 408 526 5260
             Email:  kzm@cisco.com
  Description: The MIB module for managing UDP implementations.
  Revision: 9103310000Z (The initial revision of this MIB module was
            part of MIB-II.)
)
    ::= 1.3.6.1.2.1.50

VALUE udp OBJECT IDENTIFIER
    ::= 1.3.6.1.2.1.7

VALUE udpInDatagrams OBJECT-TYPE (
  Syntax: INTEGER (0..4294967295)
  Access: read-only
  Status: current
  Description: The total number of UDP datagrams delivered to UDP users.
)
    ::= 1.3.6.1.2.1.7.1

Parsing a MIB File

The amount of processing that can be easily done on the output from the pretty-printer is clearly limited. Advanced filtering or extraction of certain features of the information requires the writing of a specialized application using the Mibble parsing library.

In order to parse a MIB file, a MIB loader must first be created. The MIB loader handles the loading session, managing all imports, and making sure that no file is loaded more than once. The MIB loader also contains an import path, which can be modified to add directories with referenced MIB files.

Below is The Java source code for a simple method for loading a MIB. Note that the directory containing the MIB file is added to the import path in this example.

import net.percederberg.mibble.*;

public Mib loadMib(File file)
    throws FileNotFoundException, MibLoaderException {

    // In real code, a single MibLoader instance should be reused
    MibLoader loader = new MibLoader();

    // The MIB file may import other MIBs (often in same dir)
    loader.addDir(file.getParentFile());

    // Once initialized, MIB loading is straight-forward
    return loader.load(file);
}

Processing a MIB file

Once the MIB file has been loaded, the contents can be accessed and processed. The sample code below demonstrates some simple methods for extracting all the names of value symbols with an object identifier value. The list of methods and accessors available can be found in the Mibble Java API.

import net.percederberg.mibble.*;
import net.percederberg.mibble.value.*;

public HashMap<String,ObjectIdentifierValue> extractOids(Mib mib) {
    HashMap<String,ObjectIdentifierValue> map = new HashMap<>();
    for (MibSymbol symbol : mib.getAllSymbols()) {
        ObjectIdentifierValue oid = extractOid(symbol);
        if (oid != null) {
            map.put(symbol.getName(), oid);
        }
    }
    return map;
}

public ObjectIdentifierValue extractOid(MibSymbol symbol) {
    if (symbol instanceof MibValueSymbol) {
        MibValue value = ((MibValueSymbol) symbol).getValue();
        if (value instanceof ObjectIdentifierValue) {
            return (ObjectIdentifierValue) value;
        }
    }
    return null;
}