use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventConfDaoReloadTest method canMaintainOrderOnReload.
/**
* Verify that the order of the includes is maintained
* when new event configuration files are added, and reloaded.
*/
@Test
public void canMaintainOrderOnReload() throws Exception {
// Copy the resources to the file system
File eventconfXml = copyEventConfig("order/eventconf.empty.xml", "eventconf.xml");
// Load
DefaultEventConfDao eventConfDao = new DefaultEventConfDao();
eventConfDao.setConfigResource(new FileSystemResource(eventconfXml));
eventConfDao.afterPropertiesSet();
assertEquals(0, eventConfDao.getAllEvents().size());
EventBuilder eb = new EventBuilder("uei.opennms.org/test/order", "JUnit");
Event event = eventConfDao.findByEvent(eb.getEvent());
assertNull("no event should match", event);
// Replace the eventconf.xml with one that references 1
Thread.sleep(1000);
copyEventConfig("order/eventconf.1.xml", "eventconf.xml");
copyEventConfig("order/1.events.xml", "1.events.xml");
// Reload
eventConfDao.reload();
assertEquals(1, eventConfDao.getAllEvents().size());
event = eventConfDao.findByEvent(eb.getEvent());
assertEquals("Critical", event.getSeverity());
// Replace the eventconf.xml with one that references 2 and then 1
Thread.sleep(1000);
copyEventConfig("order/eventconf.21.xml", "eventconf.xml");
copyEventConfig("order/2.events.xml", "2.events.xml");
// Reload
eventConfDao.reload();
assertEquals(2, eventConfDao.getAllEvents().size());
event = eventConfDao.findByEvent(eb.getEvent());
assertEquals("Major", event.getSeverity());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventConfDataTest method anticipateAndSend.
public void anticipateAndSend(String event, String version, String enterprise, int generic, int specific, String snmphost) throws Exception {
EventBuilder snmp = createEventBuilder(version, enterprise, generic, specific, snmphost);
anticipateAndSend(event, snmp.getEvent());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventConfMatcherTest method canUseMaskElementsOnEventWithUei.
/**
* NMS-9496: Verify that mask elements can be used to match
* event definitions, even when an existing UEI is set in the event.
*/
@Test
public void canUseMaskElementsOnEventWithUei() throws Exception {
EventBuilder eb = new EventBuilder("uei.opennms.org/threshold/highThresholdExceeded", "JUnit");
Event event = eventConfDao.findByEvent(eb.getEvent());
Assert.assertNull(event.getOperinstruct());
// Match first definition
eb.setNodeid(101);
event = eventConfDao.findByEvent(eb.getEvent());
Assert.assertEquals("Call Linux People", event.getOperinstruct());
Assert.assertEquals("Critical", event.getSeverity());
// Match second definition
eb.setNodeid(201);
event = eventConfDao.findByEvent(eb.getEvent());
Assert.assertEquals("Call Windows People", event.getOperinstruct());
Assert.assertEquals("Major", event.getSeverity());
// Match default
eb.setNodeid(121);
event = eventConfDao.findByEvent(eb.getEvent());
Assert.assertNull(event.getOperinstruct());
Assert.assertEquals("Minor", event.getSeverity());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class EventConfMatcherTest method canUseMaskVarbindsOnManyEventsWithSameUei.
/**
* NMS-9507: Verify that mask elements can be used to match
* event definitions, even when multiple event definitions
* with the same UEI are present.
*/
@Test
public void canUseMaskVarbindsOnManyEventsWithSameUei() throws Exception {
EventBuilder eb = new EventBuilder("uei.opennms.org/mib2events/Enterprises/PaloAlto/Panorama/panGeneralGeneralTrap", "JUnit");
eb.setGeneric(6);
eb.setSpecific(600);
eb.setEnterpriseId(".1.3.6.1.4.1.25461.2.1.3.2");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.1", "p1");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.2", "p2");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.3", "p3");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.4", "p4");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.5", "p5");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.6", "p6");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.7", "p7");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.8", "p8");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.9", "p9");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.10", "p10");
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.11", 4);
eb.addParam(".1.3.6.1.4.1.25461.2.1.3.2.1.12", "Management server shutting down");
Event event = eventConfDao.findByEvent(eb.getEvent());
Assert.assertEquals("Major", event.getSeverity());
eb.setParam(".1.3.6.1.4.1.25461.2.1.3.2.1.11", 2);
eb.setParam(".1.3.6.1.4.1.25461.2.1.3.2.1.12", "Management server started, everything is OK");
event = eventConfDao.findByEvent(eb.getEvent());
Assert.assertEquals("Cleared", event.getSeverity());
}
use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.
the class DroolsCorrelationEngine method reloadConfig.
@Override
public void reloadConfig() {
EventBuilder ebldr = new EventBuilder(EventConstants.RELOAD_DAEMON_CONFIG_SUCCESSFUL_UEI, getName());
ebldr.addParam(EventConstants.PARM_DAEMON_NAME, "DroolsCorrelationEngine-" + m_name);
try {
LOG.info("Reloading configuration for engine {}", m_name);
EngineConfiguration cfg = JaxbUtils.unmarshal(EngineConfiguration.class, m_configPath);
Optional<RuleSet> opt = cfg.getRuleSetCollection().stream().filter(rs -> rs.getName().equals(getName())).findFirst();
if (opt.isPresent()) {
marshallStateToDisk(true);
opt.get().updateEngine(this);
initialize();
} else {
ebldr.setUei(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI);
ebldr.addParam(EventConstants.PARM_REASON, "RuleSet not found on " + m_configPath);
}
} catch (Exception e) {
ebldr.setUei(EventConstants.RELOAD_DAEMON_CONFIG_FAILED_UEI);
ebldr.addParam(EventConstants.PARM_REASON, e.getMessage());
} finally {
sendEvent(ebldr.getEvent());
}
}
Aggregations