Search in sources :

Example 1 with EventTranslatorConfigFactory

use of org.opennms.netmgt.config.EventTranslatorConfigFactory in project opennms by OpenNMS.

the class EventTranslatorIT method testTranslateLinkDown.

@Test
public void testTranslateLinkDown() throws SQLException, IOException {
    InputStream rdr = new ByteArrayInputStream(getLinkDownTranslation().getBytes(StandardCharsets.UTF_8));
    m_config = new EventTranslatorConfigFactory(rdr, m_db);
    EventTranslatorConfigFactory.setInstance(m_config);
    m_translator = EventTranslator.getInstance();
    m_translator.setEventManager(m_eventMgr);
    m_translator.setConfig(EventTranslatorConfigFactory.getInstance());
    //m_translator.setDataSource(m_db);
    Connection c = m_db.getConnection();
    Statement stmt = c.createStatement();
    stmt.executeUpdate("update snmpinterface set snmpifname = 'david', snmpifalias = 'p-brane' WHERE nodeid = 1 and snmpifindex = 2");
    stmt.close();
    c.close();
    List<Event> translatedEvents = m_config.translateEvent(createLinkDownEvent());
    assertNotNull(translatedEvents);
    assertEquals(1, translatedEvents.size());
    assertEquals(3, translatedEvents.get(0).getParmCollection().size());
    assertEquals(".1.3.6.1.2.1.2.2.1.1.2", translatedEvents.get(0).getParmCollection().get(0).getParmName());
    assertEquals("ifName", translatedEvents.get(0).getParmCollection().get(1).getParmName());
    assertEquals("ifAlias", translatedEvents.get(0).getParmCollection().get(2).getParmName());
    assertEquals("david", translatedEvents.get(0).getParmCollection().get(1).getValue().getContent());
    assertEquals("p-brane", translatedEvents.get(0).getParmCollection().get(2).getValue().getContent());
}
Also used : EventTranslatorConfigFactory(org.opennms.netmgt.config.EventTranslatorConfigFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Statement(java.sql.Statement) Connection(java.sql.Connection) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 2 with EventTranslatorConfigFactory

use of org.opennms.netmgt.config.EventTranslatorConfigFactory in project opennms by OpenNMS.

the class EventTranslatorIT method setUp.

@Before
public void setUp() throws Exception {
    //        MockUtil.println("------------ Begin Test "+getName()+" --------------------------");
    MockLogAppender.setupLogging();
    createMockNetwork();
    createMockDb();
    createAnticipators();
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_eventMgr.addEventListener(m_outageAnticipator);
    m_eventMgr.setSynchronous(true);
    InputStream rdr = new ByteArrayInputStream(m_passiveStatusConfiguration.getBytes(StandardCharsets.UTF_8));
    m_config = new EventTranslatorConfigFactory(rdr, m_db);
    EventTranslatorConfigFactory.setInstance(m_config);
    m_translator = EventTranslator.getInstance();
    m_translator.setEventManager(m_eventMgr);
    m_translator.setConfig(EventTranslatorConfigFactory.getInstance());
    m_translator.setDataSource(m_db);
    m_translator.init();
    m_translator.start();
}
Also used : EventTranslatorConfigFactory(org.opennms.netmgt.config.EventTranslatorConfigFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Before(org.junit.Before)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 EventTranslatorConfigFactory (org.opennms.netmgt.config.EventTranslatorConfigFactory)2 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 Before (org.junit.Before)1 Test (org.junit.Test)1 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)1 Event (org.opennms.netmgt.xml.event.Event)1