Search in sources :

Example 1 with EventExpander

use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.

the class VacuumdIT method setUp.

@Before
public void setUp() throws Exception {
    m_network.createStandardNetwork();
    InputStream is = ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/vacuumd/vacuumd-configuration.xml");
    try {
        VacuumdConfigFactory.setInstance(new VacuumdConfigFactory(is));
    } finally {
        IOUtils.closeQuietly(is);
    }
    m_eventdIpcMgr.setEventWriter(m_database);
    EventExpander expander = new EventExpander(new MetricRegistry());
    expander.setEventConfDao(new EmptyEventConfDao());
    m_eventdIpcMgr.setEventExpander(expander);
    Vacuumd.destroySingleton();
    m_vacuumd = Vacuumd.getSingleton();
    m_vacuumd.setEventManager(m_eventdIpcMgr);
    m_vacuumd.init();
    // Insert some empty nodes to avoid foreign-key violations on subsequent events/alarms
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "default-1");
    node.setId(1);
    m_nodeDao.save(node);
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "default-2");
    node.setId(2);
    m_nodeDao.save(node);
    m_nodeDao.flush();
    MockUtil.println("------------ Finished setup for: " + this.getClass().getName() + " --------------------------");
}
Also used : VacuumdConfigFactory(org.opennms.netmgt.config.VacuumdConfigFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) EventExpander(org.opennms.netmgt.eventd.EventExpander) InputStream(java.io.InputStream) MetricRegistry(com.codahale.metrics.MetricRegistry) EmptyEventConfDao(org.opennms.netmgt.dao.mock.MockEventIpcManager.EmptyEventConfDao) Before(org.junit.Before)

Example 2 with EventExpander

use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.

the class EventExpanderTest method testAfterPropertiesSetWithNoEventConfDao.

@Test
public void testAfterPropertiesSetWithNoEventConfDao() {
    m_mocks.replayAll();
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("property eventConfDao must be set"));
    EventExpander expander = new EventExpander(new MetricRegistry());
    try {
        expander.afterPropertiesSet();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : EventExpander(org.opennms.netmgt.eventd.EventExpander) MetricRegistry(com.codahale.metrics.MetricRegistry) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 3 with EventExpander

use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.

the class EventExpanderTest method testAfterPropertiesSet.

@Test
public void testAfterPropertiesSet() {
    m_mocks.replayAll();
    EventExpander expander = new EventExpander(new MetricRegistry());
    expander.setEventConfDao(m_eventConfDao);
    expander.setEventUtil(m_eventUtil);
    expander.afterPropertiesSet();
}
Also used : EventExpander(org.opennms.netmgt.eventd.EventExpander) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 4 with EventExpander

use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.

the class EventExpanderTest method testOptionalParameters.

@Test
public void testOptionalParameters() {
    String uei = "uei.opennms.org/testEventWithOptionalParameters";
    EventBuilder builder = new EventBuilder(uei, "something");
    builder.addParam("worst-framework-ever", "Vaadin");
    Event event = builder.getEvent();
    EventExpander expander = new EventExpander(new MetricRegistry());
    expander.setEventConfDao(m_eventConfDao);
    expander.setEventUtil(m_eventUtil);
    expander.afterPropertiesSet();
    org.opennms.netmgt.xml.eventconf.Event eventConfig = new org.opennms.netmgt.xml.eventconf.Event();
    eventConfig.setUei(uei);
    org.opennms.netmgt.xml.eventconf.Parameter p1 = new org.opennms.netmgt.xml.eventconf.Parameter();
    p1.setName("username");
    p1.setValue("agalue");
    eventConfig.addParameter(p1);
    org.opennms.netmgt.xml.eventconf.Parameter p2 = new org.opennms.netmgt.xml.eventconf.Parameter();
    p2.setName("i-hate");
    p2.setValue("%parm[#1]%");
    p2.setExpand(true);
    eventConfig.addParameter(p2);
    EasyMock.expect(m_eventConfDao.findByEvent(event)).andReturn(eventConfig);
    EasyMock.expect(m_eventConfDao.isSecureTag(EasyMock.anyObject())).andReturn(true).anyTimes();
    EasyMock.expect(m_eventUtil.expandParms("%parm[#1]%", event, new HashMap<String, Map<String, String>>())).andReturn("Vaadin");
    m_mocks.replayAll();
    expander.expandEvent(event);
    assertEquals("event UEI", uei, event.getUei());
    assertEquals("parameters count", 3, event.getParmCollection().size());
    assertNotNull(event.getParm("username"));
    assertEquals("parameter value", "agalue", event.getParm("username").getValue().getContent());
    assertEquals("parameter value", "Vaadin", event.getParm("i-hate").getValue().getContent());
}
Also used : EventExpander(org.opennms.netmgt.eventd.EventExpander) MetricRegistry(com.codahale.metrics.MetricRegistry) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with EventExpander

use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.

the class EventExpanderTest method testExpandEventWithNoDaoMatches.

@Test
public void testExpandEventWithNoDaoMatches() {
    String uei = "uei.opennms.org/internal/capsd/snmpConflictsWithDb";
    EventBuilder builder = new EventBuilder(uei, "something");
    EventExpander expander = new EventExpander(new MetricRegistry());
    expander.setEventConfDao(m_eventConfDao);
    expander.setEventUtil(m_eventUtil);
    expander.afterPropertiesSet();
    Event event = builder.getEvent();
    assertNull("event description should be null before expandEvent is called", event.getDescr());
    EasyMock.expect(m_eventConfDao.findByEvent(event)).andReturn(null);
    EasyMock.expect(m_eventConfDao.findByUei("uei.opennms.org/default/event")).andReturn(null);
    m_mocks.replayAll();
    expander.expandEvent(event);
    assertEquals("event UEI", uei, event.getUei());
// assertNotNull("event description should not be null after expandEvent is called", event.getDescr());
// 
// String matchText = "During a rescan";
// assertTrue("event description should contain '" + matchText + "'", event.getDescr().contains(matchText));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventExpander(org.opennms.netmgt.eventd.EventExpander) MetricRegistry(com.codahale.metrics.MetricRegistry) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Aggregations

EventExpander (org.opennms.netmgt.eventd.EventExpander)6 MetricRegistry (com.codahale.metrics.MetricRegistry)5 Test (org.junit.Test)4 Before (org.junit.Before)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 Event (org.opennms.netmgt.xml.event.Event)2 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DefaultEventConfDao (org.opennms.netmgt.config.DefaultEventConfDao)1 SnmpPeerFactory (org.opennms.netmgt.config.SnmpPeerFactory)1 VacuumdConfigFactory (org.opennms.netmgt.config.VacuumdConfigFactory)1 JdbcEventdServiceManager (org.opennms.netmgt.dao.mock.JdbcEventdServiceManager)1 EmptyEventConfDao (org.opennms.netmgt.dao.mock.MockEventIpcManager.EmptyEventConfDao)1 BroadcastEventProcessor (org.opennms.netmgt.eventd.BroadcastEventProcessor)1 DefaultEventHandlerImpl (org.opennms.netmgt.eventd.DefaultEventHandlerImpl)1 EventIpcManagerDefaultImpl (org.opennms.netmgt.eventd.EventIpcManagerDefaultImpl)1 Eventd (org.opennms.netmgt.eventd.Eventd)1