Search in sources :

Example 96 with EventBuilder

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.eventconf.Event) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 97 with EventBuilder

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 98 with EventBuilder

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.eventconf.Event) Test(org.junit.Test)

Example 99 with EventBuilder

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.eventconf.Event) Test(org.junit.Test)

Example 100 with EventBuilder

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());
    }
}
Also used : EngineConfiguration(org.opennms.netmgt.correlation.drools.config.EngineConfiguration) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) EventConstants(org.opennms.netmgt.events.api.EventConstants) AbstractCorrelationEngine(org.opennms.netmgt.correlation.AbstractCorrelationEngine) Meter(com.codahale.metrics.Meter) Level(org.kie.api.builder.Message.Level) Event(org.opennms.netmgt.xml.event.Event) Map(java.util.Map) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) KieServices(org.kie.api.KieServices) JaxbUtils(org.opennms.core.xml.JaxbUtils) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Path(java.nio.file.Path) KieMarshallers(org.kie.api.marshalling.KieMarshallers) AssertBehaviour(org.drools.core.RuleBaseConfiguration.AssertBehaviour) Resource(org.springframework.core.io.Resource) KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilder(org.kie.api.builder.KieBuilder) Logger(org.slf4j.Logger) MetricRegistry(com.codahale.metrics.MetricRegistry) EventProcessingOption(org.kie.api.conf.EventProcessingOption) Collection(java.util.Collection) Logging(org.opennms.core.logging.Logging) FileOutputStream(java.io.FileOutputStream) KieContainer(org.kie.api.runtime.KieContainer) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) ApplicationContext(org.springframework.context.ApplicationContext) File(java.io.File) DroolsParserException(org.drools.compiler.compiler.DroolsParserException) List(java.util.List) Paths(java.nio.file.Paths) RuleSet(org.opennms.netmgt.correlation.drools.config.RuleSet) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) Marshaller(org.kie.api.marshalling.Marshaller) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) Gauge(com.codahale.metrics.Gauge) InputStream(java.io.InputStream) RuleSet(org.opennms.netmgt.correlation.drools.config.RuleSet) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EngineConfiguration(org.opennms.netmgt.correlation.drools.config.EngineConfiguration) IOException(java.io.IOException) DroolsParserException(org.drools.compiler.compiler.DroolsParserException)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)305 Test (org.junit.Test)88 Event (org.opennms.netmgt.xml.event.Event)84 Date (java.util.Date)22 OnmsNode (org.opennms.netmgt.model.OnmsNode)17 InetAddress (java.net.InetAddress)16 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)15 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)12 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 Parm (org.opennms.netmgt.xml.event.Parm)9 Event (org.opennms.netmgt.xml.eventconf.Event)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)6