use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.
the class JsmiMibParserTest method testNotifications.
/**
* Test generate events from notifications.
*
* @throws Exception the exception
*/
@Test
public void testNotifications() throws Exception {
if (parser.parseMib(new File(MIB_DIR, "IF-MIB.txt"))) {
Events events = parser.getEvents("uei.opennms.org/traps/ifmib");
Assert.assertNotNull(events);
System.out.println(JaxbUtils.marshal(events));
Assert.assertEquals(2, events.getEvents().size());
Event event = null;
for (Event e : events.getEvents()) {
if (e.getUei().contains("linkDown"))
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("IF-MIB defined trap event: linkDown", event.getEventLabel());
Assert.assertNotNull(event.getMask());
for (final Maskelement me : event.getMask().getMaskelements()) {
if (me.getMename().equals("id"))
Assert.assertEquals(".1.3.6.1.6.3.1.1.5", me.getMevalues().get(0));
if (me.getMename().equals("generic"))
Assert.assertEquals("6", me.getMevalues().get(0));
if (me.getMename().equals("specific"))
Assert.assertEquals("3", me.getMevalues().get(0));
}
Assert.assertEquals(2, event.getVarbindsdecodes().size());
for (Varbindsdecode vb : event.getVarbindsdecodes()) {
if (vb.getParmid().equals("parm[#2]"))
Assert.assertEquals(3, vb.getDecodes().size());
if (vb.getParmid().equals("parm[#3]"))
Assert.assertEquals(7, vb.getDecodes().size());
}
} else {
Assert.fail("The IF-MIB.txt file couldn't be parsed successfully.");
}
}
use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.
the class EventconfFactoryIT method testReload.
//Ensure reload does indeed reload fresh data
@Test
public void testReload() throws Exception {
m_eventConfDao.setConfigResource(new ClassPathResource(getResourceForRelativePath("eventconf-speedtest/eventconf.xml")));
String newUEI = "uei.opennms.org/custom/newTestUEI";
List<Event> events = m_eventConfDao.getEvents(knownUEI1);
Event event = (Event) events.get(0);
event.setUei(newUEI);
//Check that the new UEI is there
List<Event> events2 = m_eventConfDao.getEvents(newUEI);
Event event2 = ((Event) events2.get(0));
assertNotNull("Must have some events", event2);
assertEquals("Must be exactly 1 event", 1, events2.size());
assertEquals("uei must be the new one", newUEI, event2.getUei());
//Now reload without saving - should not find the new one, but should find the old one
try {
m_eventConfDao.reload();
} catch (Throwable e) {
e.printStackTrace();
fail("Should not have had exception while reloading factory " + e.getMessage());
}
List<Event> events3 = m_eventConfDao.getEvents(knownUEI1);
assertNotNull("Must have some events", events3);
assertEquals("Must be exactly 1 event", 1, events3.size());
Event event3 = (Event) events3.get(0);
assertEquals("uei must be the new one", knownUEI1, event3.getUei());
//Check that the new UEI is *not* there this time
List<Event> events4 = m_eventConfDao.getEvents(newUEI);
assertNull("Must be no events by that name", events4);
}
use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.
the class EventconfFactoryIT method testFindByEventUeiKnown1000Times.
@Test
public void testFindByEventUeiKnown1000Times() throws Exception {
final int ATTEMPTS = 10000;
// knownUEI1 is currently set to 'uei.opennms.org/internal/capsd/snmpConflictsWithDb'
// and is defined in the root of the eventconf that is loaded bellow.
// Prior to this commit, this test would produce very different results
// when running against another UEI i.e. 'uei.opennms.org/default/event'
// that happens to be the last event defined in the last included file
EventBuilder bldr = new EventBuilder(knownUEI1, "testFindByEventUeiKnown");
DefaultEventConfDao eventConfDao = loadConfiguration("eventconf-speedtest/eventconf.xml");
Event eventConf = null;
org.opennms.netmgt.xml.event.Event event = bldr.getEvent();
long start = System.currentTimeMillis();
for (int i = 0; i < ATTEMPTS; i++) {
eventConf = eventConfDao.findByEvent(event);
}
long end = System.currentTimeMillis();
long elapsed = end - start;
System.err.printf("%d Attempts: Elapsed: %d ms: events per second %f.%n", ATTEMPTS, elapsed, ATTEMPTS * 1000.0 / elapsed);
assertNotNull("returned event configuration for event with known UEI '" + knownUEI1 + "' should not be null", eventConf);
assertEquals("UEI", bldr.getEvent().getUei(), eventConf.getUei());
}
use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.
the class EventconfFactoryIT method testFindByTrapWithWildcard.
@Test
public void testFindByTrapWithWildcard() throws Exception {
String enterpriseId = ".1.3.6.1.4.1.253.1.2.3";
int generic = 6;
int specific = 1;
String ip = "127.0.0.1";
EventBuilder bldr = new EventBuilder(null, "trapd");
bldr.setSnmpVersion("v2");
bldr.setCommunity("public");
bldr.setHost(ip);
bldr.setSnmpHost(ip);
bldr.setInterface(InetAddress.getByName("127.0.0.1"));
// time-stamp (units is hundreths of a second
bldr.setSnmpTimeStamp(System.currentTimeMillis() / 10);
bldr.setGeneric(generic);
bldr.setSpecific(specific);
bldr.setEnterpriseId(enterpriseId);
for (int i = 0; i < 19; i++) {
bldr.addParam(".1.3.6." + (i + 1), "parm" + (i + 1));
}
DefaultEventConfDao eventConfDao = loadConfiguration("eventconf-wildcard/eventconf.xml");
org.opennms.netmgt.xml.event.Event event = bldr.getEvent();
Event eventConf = eventConfDao.findByEvent(event);
assertNotNull("returned event configuration for eclipsed trap '" + enterpriseId + "' should not be null", eventConf);
assertEquals("uei.opennms.org/vendor/Xerox/traps/EnterpriseDefault", eventConf.getUei());
}
use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.
the class EventconfFactoryIT method testFindByUeiUnknown.
@Test
public void testFindByUeiUnknown() {
Event eventConf = m_eventConfDao.findByUei(unknownUEI1);
assertNull("returned event configuration for unknown UEI '" + unknownUEI1 + "' should be null", eventConf);
}
Aggregations