Search in sources :

Example 1 with IntegerType

use of net.percederberg.mibble.type.IntegerType 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)

Example 2 with IntegerType

use of net.percederberg.mibble.type.IntegerType in project opennms by OpenNMS.

the class Mib2Events method getTrapVarbindsDecode.

private static List<Varbindsdecode> getTrapVarbindsDecode(MibValueSymbol trapValueSymbol) {
    Map<String, Varbindsdecode> decode = new LinkedHashMap<String, Varbindsdecode>();
    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
        String parmName = "parm[#" + vbNum + "]";
        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());
                }
                for (Entry<Integer, String> entry : map.entrySet()) {
                    if (!decode.containsKey(parmName)) {
                        Varbindsdecode newVarbind = new Varbindsdecode();
                        newVarbind.setParmid(parmName);
                        decode.put(newVarbind.getParmid(), newVarbind);
                    }
                    Decode d = new Decode();
                    d.setVarbinddecodedstring(entry.getValue());
                    d.setVarbindvalue(entry.getKey().toString());
                    decode.get(parmName).addDecode(d);
                }
            }
        }
        vbNum++;
    }
    return new ArrayList<Varbindsdecode>(decode.values());
}
Also used : Varbindsdecode(org.opennms.netmgt.xml.eventconf.Varbindsdecode) MibValue(net.percederberg.mibble.MibValue) ArrayList(java.util.ArrayList) Decode(org.opennms.netmgt.xml.eventconf.Decode) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) IntegerType(net.percederberg.mibble.type.IntegerType) SnmpObjectType(net.percederberg.mibble.snmp.SnmpObjectType) MibValueSymbol(net.percederberg.mibble.MibValueSymbol)

Aggregations

TreeMap (java.util.TreeMap)2 MibValue (net.percederberg.mibble.MibValue)2 MibValueSymbol (net.percederberg.mibble.MibValueSymbol)2 SnmpObjectType (net.percederberg.mibble.snmp.SnmpObjectType)2 IntegerType (net.percederberg.mibble.type.IntegerType)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 SnmpType (net.percederberg.mibble.snmp.SnmpType)1 Decode (org.opennms.netmgt.xml.eventconf.Decode)1 Varbindsdecode (org.opennms.netmgt.xml.eventconf.Varbindsdecode)1