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.");
}
}
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);
}
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;
}
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());
}
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());
}
Aggregations