Search in sources :

Example 6 with Varbindsdecode

use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.

the class JsmiMibParserTest method testTraps.

/**
     * Test generate events from traps.
     */
@Test
public void testTraps() {
    if (parser.parseMib(new File(MIB_DIR, "RFC1269-MIB.txt"))) {
        Assert.assertEquals("RFC1269-MIB", parser.getMibName());
        Events events = parser.getEvents("uei.opennms.org/traps/RFC1269");
        Assert.assertNotNull(events);
        Assert.assertEquals(2, events.getEvents().size());
        System.out.println(JaxbUtils.marshal(events));
        Assert.assertEquals(2, events.getEvents().size());
        Event event = null;
        for (Event e : events.getEvents()) {
            if (e.getUei().contains("bgpBackwardTransition"))
                event = e;
        }
        Assert.assertNotNull(event);
        // TODO Must be more specific
        Assert.assertNotNull(event.getDescr());
        Assert.assertNotNull(event.getLogmsg());
        // TODO Must be more specific
        Assert.assertNotNull(event.getLogmsg().getContent());
        Assert.assertEquals("Indeterminate", event.getSeverity());
        Assert.assertEquals("RFC1269-MIB defined trap event: bgpBackwardTransition", event.getEventLabel());
        Assert.assertNotNull(event.getMask());
        for (final Maskelement me : event.getMask().getMaskelements()) {
            if (me.getMename().equals("id"))
                Assert.assertEquals(".1.3.6.1.2.1.15", me.getMevalues().get(0));
            if (me.getMename().equals("generic"))
                Assert.assertEquals("6", me.getMevalues().get(0));
            if (me.getMename().equals("specific"))
                Assert.assertEquals("2", me.getMevalues().get(0));
        }
        Assert.assertEquals(1, event.getVarbindsdecodes().size());
        for (Varbindsdecode vb : event.getVarbindsdecodes()) {
            if (vb.getParmid().equals("parm[#3]"))
                Assert.assertEquals(6, vb.getDecodes().size());
        }
    } else {
        Assert.fail("The RFC1269-MIB.txt file couldn't be parsed successfully.");
    }
}
Also used : Events(org.opennms.netmgt.xml.eventconf.Events) Varbindsdecode(org.opennms.netmgt.xml.eventconf.Varbindsdecode) Event(org.opennms.netmgt.xml.eventconf.Event) Maskelement(org.opennms.netmgt.xml.eventconf.Maskelement) File(java.io.File) Test(org.junit.Test)

Example 7 with Varbindsdecode

use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.

the class VarbindsDecodeField method addHandler.

/**
     * Adds the handler.
     */
private void addHandler() {
    Varbindsdecode v = new Varbindsdecode();
    v.setParmid("??");
    container.addOnmsBean(v);
}
Also used : Varbindsdecode(org.opennms.netmgt.xml.eventconf.Varbindsdecode)

Example 8 with Varbindsdecode

use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.

the class Mib2Events method getTrapEvent.

public Event getTrapEvent(MibValueSymbol trapValueSymbol, String ueibase) {
    Event evt = new Event();
    // Set the event's UEI, event-label, logmsg, severity, and descr
    evt.setUei(getTrapEventUEI(trapValueSymbol, ueibase));
    evt.setEventLabel(getTrapEventLabel(trapValueSymbol));
    evt.setLogmsg(getTrapEventLogmsg(trapValueSymbol));
    evt.setSeverity("Indeterminate");
    evt.setDescr(getTrapEventDescr(trapValueSymbol));
    if (!m_compat) {
    //evt.setAlarmData(getTrapEventAlarmData());
    }
    if (!m_compat) {
        List<Varbindsdecode> decode = getTrapVarbindsDecode(trapValueSymbol);
        if (!decode.isEmpty()) {
            evt.setVarbindsdecode(decode);
        }
    }
    evt.setMask(new Mask());
    // The "ID" mask element (trap enterprise)
    addMaskElement(evt, "id", getTrapEnterprise(trapValueSymbol));
    // The "generic" mask element: hard-wired to enterprise-specific(6)
    addMaskElement(evt, "generic", "6");
    // The "specific" mask element (trap specific-type)
    addMaskElement(evt, "specific", getTrapSpecificType(trapValueSymbol));
    return evt;
}
Also used : Varbindsdecode(org.opennms.netmgt.xml.eventconf.Varbindsdecode) Mask(org.opennms.netmgt.xml.eventconf.Mask) Event(org.opennms.netmgt.xml.eventconf.Event)

Example 9 with Varbindsdecode

use of org.opennms.netmgt.xml.eventconf.Varbindsdecode 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)

Example 10 with Varbindsdecode

use of org.opennms.netmgt.xml.eventconf.Varbindsdecode in project opennms by OpenNMS.

the class SpectrumUtilsTest method translateSimpleEventTable.

@Test
public void translateSimpleEventTable() {
    EventTable et = new EventTable("foobar");
    et.put(1, "foo");
    et.put(2, "bar");
    et.put(3, "baz");
    Varbindsdecode vbd = m_utils.translateEventTable(et, "parm[#1]");
    Assert.assertEquals("Parm ID is parm[#1]", "parm[#1]", vbd.getParmid());
    Assert.assertEquals("Three decode elements", 3, vbd.getDecodeCount());
    Assert.assertEquals("First key is 1", "1", vbd.getDecode(0).getVarbindvalue());
    Assert.assertEquals("First value is foo", "foo", vbd.getDecode(0).getVarbinddecodedstring());
    Assert.assertEquals("Second key is 2", "2", vbd.getDecode(1).getVarbindvalue());
    Assert.assertEquals("Second value is bar", "bar", vbd.getDecode(1).getVarbinddecodedstring());
    Assert.assertEquals("Third key is 3", "3", vbd.getDecode(2).getVarbindvalue());
    Assert.assertEquals("Third value is baz", "baz", vbd.getDecode(2).getVarbinddecodedstring());
}
Also used : Varbindsdecode(org.opennms.netmgt.xml.eventconf.Varbindsdecode) Test(org.junit.Test)

Aggregations

Varbindsdecode (org.opennms.netmgt.xml.eventconf.Varbindsdecode)11 ArrayList (java.util.ArrayList)4 Decode (org.opennms.netmgt.xml.eventconf.Decode)4 Event (org.opennms.netmgt.xml.eventconf.Event)4 Test (org.junit.Test)3 File (java.io.File)2 LinkedHashMap (java.util.LinkedHashMap)2 TreeMap (java.util.TreeMap)2 Events (org.opennms.netmgt.xml.eventconf.Events)2 Mask (org.opennms.netmgt.xml.eventconf.Mask)2 Maskelement (org.opennms.netmgt.xml.eventconf.Maskelement)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 MibValue (net.percederberg.mibble.MibValue)1 MibValueSymbol (net.percederberg.mibble.MibValueSymbol)1 SnmpObjectType (net.percederberg.mibble.snmp.SnmpObjectType)1 IntegerType (net.percederberg.mibble.type.IntegerType)1