/ Docs / Introduction

Introduction to Mibble

Mibble is an SNMP (Simple Network Managment Protocol) MIB (Manageable Information Base) parser library for Java. The library can be used to read SNMP MIB files as well as simple ASN.1 files. The library also contains classes for simple handling of the information contained in the MIB file, such as OID:s and types.

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, two small utilities available for testing the library – a pretty-printer, and a validator.

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. See figure 1 below for an example of the pretty-printer output.

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

Figure 1. The pretty-printer output for a part of the UDP-MIB file. Note the complete object identifiers present for each value

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, 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. Using the MIB loader for loading a MIB file is illustrated in figure 2 below.

import net.percederberg.mibble.Mib;
import net.percederberg.mibble.MibLoader;
import net.percederberg.mibble.MibLoaderException;

...

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

    MibLoader  loader = new MibLoader();

    loader.addDir(file.getParentFile());
    return loader.load(file);
}

Figure 2. The Java source code for a simple MIB parsing function using Mibble. Note the directory containing the MIB file is added to the import path in this example.

Processing a MIB file

Once the MIB file has been loaded, the contents can be accessed and processed. Figure 3 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.Mib;
import net.percederberg.mibble.MibSymbol;
import net.percederberg.mibble.MibValue;
import net.percederberg.mibble.MibValueSymbol;
import net.percederberg.mibble.value.ObjectIdentifierValue;

...

public HashMap extractOids(Mib mib) {
    HashMap    map = new HashMap();
    Iterator   iter = mib.getAllSymbols().iterator();
    MibSymbol  symbol;
    MibValue   value;

    while (iter.hasNext()) {
        symbol = (MibSymbol) iter.next();
        value = extractOid(symbol);
        if (value != null) {
            map.put(symbol.getName(), value);
        }
    }
    return map;
}

public ObjectIdentifierValue extractOid(MibSymbol symbol) {
    MibValue  value;

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

Figure 3. The Java source code for extracting a map of the symbol names and the object identifiers.


Copyright © 2003-2007 Per Cederberg. Permission is granted to copy this document verbatim in any medium, provided that this copyright notice is left intact.

Designed & Hosted by Liquid Site Hosting.