Search in sources :

Example 1 with SnmpType

use of net.percederberg.mibble.snmp.SnmpType in project opennms by OpenNMS.

the class Mib2Events method getTrapEventDescr.

public static String getTrapEventDescr(MibValueSymbol trapValueSymbol) {
    String description = ((SnmpType) trapValueSymbol.getType()).getDescription();
    // FIXME There a lot of detail here (like removing the last \n) that can go away when we don't need to match mib2opennms exactly
    final String descrStartingNewlines = description.replaceAll("^", "\n<p>");
    final String descrEndingNewlines = descrStartingNewlines.replaceAll("$", "</p>\n");
    //final String descrTabbed = descrEndingNewlines.replaceAll("(?m)^", "\t");
    //final StringBuffer dbuf = new StringBuffer(descrTabbed);
    final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
        // delete the \n at the end
        dbuf.deleteCharAt(dbuf.length() - 1);
    }
    //if (dbuf.lastIndexOf("\n") != -1) {
    //    dbuf.insert(dbuf.lastIndexOf("\n") + 1, '\t');
    //}
    //final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    //dbuf.append("\n");
    dbuf.append("<table>");
    dbuf.append("\n");
    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
        dbuf.append("\t<tr><td><b>\n\n\t").append(vb.getName());
        dbuf.append("</b></td><td>\n\t%parm[#").append(vbNum).append("]%;</td><td><p>");
        SnmpObjectType snmpObjectType = ((SnmpObjectType) ((ObjectIdentifierValue) vb).getSymbol().getType());
        if (snmpObjectType.getSyntax().getClass().equals(IntegerType.class)) {
            IntegerType integerType = (IntegerType) snmpObjectType.getSyntax();
            if (integerType.getAllSymbols().length > 0) {
                SortedMap<Integer, String> map = new TreeMap<Integer, String>();
                for (MibValueSymbol sym : integerType.getAllSymbols()) {
                    map.put(new Integer(sym.getValue().toString()), sym.getName());
                }
                dbuf.append("\n");
                for (Entry<Integer, String> entry : map.entrySet()) {
                    dbuf.append("\t\t").append(entry.getValue()).append("(").append(entry.getKey()).append(")\n");
                }
                dbuf.append("\t");
            }
        }
        dbuf.append("</p></td></tr>\n");
        vbNum++;
    }
    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
        // delete the \n at the end
        dbuf.deleteCharAt(dbuf.length() - 1);
    }
    dbuf.append("</table>\n\t");
    return dbuf.toString();
}
Also used : IntegerType(net.percederberg.mibble.type.IntegerType) MibValue(net.percederberg.mibble.MibValue) SnmpObjectType(net.percederberg.mibble.snmp.SnmpObjectType) SnmpType(net.percederberg.mibble.snmp.SnmpType) MibValueSymbol(net.percederberg.mibble.MibValueSymbol) TreeMap(java.util.TreeMap)

Aggregations

TreeMap (java.util.TreeMap)1 MibValue (net.percederberg.mibble.MibValue)1 MibValueSymbol (net.percederberg.mibble.MibValueSymbol)1 SnmpObjectType (net.percederberg.mibble.snmp.SnmpObjectType)1 SnmpType (net.percederberg.mibble.snmp.SnmpType)1 IntegerType (net.percederberg.mibble.type.IntegerType)1