Search in sources :

Example 1 with MibValueSymbol

use of net.percederberg.mibble.MibValueSymbol in project opennms by OpenNMS.

the class Mib2Events method convertMibToEvents.

public Events convertMibToEvents(Mib mib, String ueibase) {
    Events events = new Events();
    for (MibSymbol sym : getAllSymbolsFromMib(mib)) {
        if (!(sym instanceof MibValueSymbol)) {
            continue;
        }
        MibValueSymbol vsym = (MibValueSymbol) sym;
        if ((!(vsym.getType() instanceof SnmpNotificationType)) && (!(vsym.getType() instanceof SnmpTrapType))) {
            continue;
        }
        events.addEvent(getTrapEvent(vsym, ueibase));
    }
    return events;
}
Also used : SnmpTrapType(net.percederberg.mibble.snmp.SnmpTrapType) Events(org.opennms.netmgt.xml.eventconf.Events) MibValueSymbol(net.percederberg.mibble.MibValueSymbol) SnmpNotificationType(net.percederberg.mibble.snmp.SnmpNotificationType) MibSymbol(net.percederberg.mibble.MibSymbol)

Example 2 with MibValueSymbol

use of net.percederberg.mibble.MibValueSymbol 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 3 with MibValueSymbol

use of net.percederberg.mibble.MibValueSymbol 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

MibValueSymbol (net.percederberg.mibble.MibValueSymbol)3 TreeMap (java.util.TreeMap)2 MibValue (net.percederberg.mibble.MibValue)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 MibSymbol (net.percederberg.mibble.MibSymbol)1 SnmpNotificationType (net.percederberg.mibble.snmp.SnmpNotificationType)1 SnmpTrapType (net.percederberg.mibble.snmp.SnmpTrapType)1 SnmpType (net.percederberg.mibble.snmp.SnmpType)1 Decode (org.opennms.netmgt.xml.eventconf.Decode)1 Events (org.opennms.netmgt.xml.eventconf.Events)1 Varbindsdecode (org.opennms.netmgt.xml.eventconf.Varbindsdecode)1