Search in sources :

Example 91 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class Nms4335IT method doMessageTest.

/**
 * Send a raw syslog message and expect a given event as a result
 *
 * @param testPDU The raw syslog message as it would appear on the wire (just the UDP payload)
 * @param expectedHost The host from which the event should be resolved as originating
 * @param expectedUEI The expected UEI of the resulting event
 * @param expectedLogMsg The expected contents of the logmsg for the resulting event
 *
 * @throws UnknownHostException
 * @throws InterruptedException
 * @throws ExecutionException
 */
private List<Event> doMessageTest(String testPDU, String expectedHost, String expectedUEI, String expectedLogMsg) throws UnknownHostException, InterruptedException, ExecutionException {
    SyslogdTestUtils.startSyslogdGracefully(m_syslogd);
    final EventBuilder expectedEventBldr = new EventBuilder(expectedUEI, "syslogd");
    expectedEventBldr.setInterface(addr(expectedHost));
    expectedEventBldr.setLogDest("logndisplay");
    expectedEventBldr.setLogMessage(expectedLogMsg);
    m_eventIpcManager.getEventAnticipator().anticipateEvent(expectedEventBldr.getEvent());
    final SyslogSinkConsumer syslogSinkConsumer = new SyslogSinkConsumer(new MetricRegistry());
    syslogSinkConsumer.setDistPollerDao(m_distPollerDao);
    syslogSinkConsumer.setSyslogdConfig(m_config);
    syslogSinkConsumer.setEventForwarder(m_eventIpcManager);
    final SyslogSinkModule syslogSinkModule = syslogSinkConsumer.getModule();
    final SyslogClient sc = new SyslogClient(null, 10, SyslogClient.LOG_DAEMON, addr("127.0.0.1"));
    final DatagramPacket pkt = sc.getPacket(SyslogClient.LOG_DEBUG, testPDU);
    final SyslogMessageLogDTO messageLog = syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
    syslogSinkConsumer.handleMessage(messageLog);
    m_eventIpcManager.getEventAnticipator().verifyAnticipated(5000, 0, 0, 0, 0);
    final Event receivedEvent = m_eventIpcManager.getEventAnticipator().getAnticipatedEventsReceived().get(0);
    assertEquals("Log messages do not match", expectedLogMsg, receivedEvent.getLogmsg().getContent());
    return m_eventIpcManager.getEventAnticipator().getAnticipatedEventsReceived();
}
Also used : SyslogMessageLogDTO(org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) MetricRegistry(com.codahale.metrics.MetricRegistry) DatagramPacket(java.net.DatagramPacket) Event(org.opennms.netmgt.xml.event.Event) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection)

Example 92 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class SyslogSinkConsumerNewSuspectIT method testUpdateInterfaceToNodeCache.

@Test
@Transactional
public void testUpdateInterfaceToNodeCache() throws Exception {
    // The cache has not been sync'd with the database yet
    assertEquals(0, m_cache.size());
    final Integer nodeId = m_databasePopulator.getNode1().getId();
    // One of the interfaces on node1
    final InetAddress addr = InetAddressUtils.addr("192.168.1.3");
    final byte[] bytes = ("<34>1 2010-08-19T22:14:15.000Z " + InetAddressUtils.str(addr) + " - - - - \uFEFFfoo0: load test 0 on tty1\0").getBytes();
    final DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, addr, SyslogClient.PORT);
    // Create a new SyslogConnection and call it to create the processed event
    Event e = dispatchAndCapture(new SyslogConnection(pkt, false));
    // The node is not present so nodeID should be blank
    Long foundid = e.getNodeid();
    LOG.debug("Found node ID: {}", foundid);
    assertTrue("Node ID was unexpectedly present: " + e.getNodeid(), foundid < 1);
    // Simulate a nodeGainedInterface event
    EventBuilder builder = new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, getClass().getSimpleName());
    builder.setNodeid(nodeId);
    builder.setInterface(addr);
    m_processor.handleNodeGainedInterface(builder.getEvent());
    // The entry was added to the cache
    assertEquals(1, m_cache.size());
    e = dispatchAndCapture(new SyslogConnection(pkt, false));
    // Assert that the event was associated with the node correctly
    foundid = e.getNodeid();
    LOG.debug("Found node ID: {}", foundid);
    assertEquals("Node ID was not present: " + e.getNodeid(), Long.valueOf(nodeId.longValue()), foundid);
    // Simulate an interfaceDeleted event
    builder = new EventBuilder(EventConstants.INTERFACE_DELETED_EVENT_UEI, getClass().getSimpleName());
    builder.setNodeid(nodeId);
    builder.setInterface(addr);
    m_processor.handleInterfaceDeleted(builder.getEvent());
    // The entry was removed from the cache
    assertEquals(0, m_cache.size());
    e = dispatchAndCapture(new SyslogConnection(pkt, false));
    // Assert that the event is no longer associated with the node
    assertTrue("Node ID was unexpectedly present: " + e.getNodeid(), e.getNodeid() < 1);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) DatagramPacket(java.net.DatagramPacket) Event(org.opennms.netmgt.xml.event.Event) SyslogConnection(org.opennms.netmgt.syslogd.api.SyslogConnection) InetAddress(java.net.InetAddress) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 93 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class ConfigureSnmpTest method testSnmpEventInfoClassWithSpecific.

/**
 * Tests getting the correct SNMP Peer after a configureSNMP event and merge to the running config.
 * @throws UnknownHostException
 */
public void testSnmpEventInfoClassWithSpecific() throws UnknownHostException {
    final String addr = "192.168.0.5";
    EventBuilder bldr = createConfigureSnmpEventBuilder(addr, null);
    addCommunityStringToEvent(bldr, "abc");
    SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent());
    SnmpPeerFactory.getInstance().define(info);
    SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr));
    assertEquals(InetAddressUtils.str(agent.getAddress()), addr);
    assertEquals("abc", agent.getReadCommunity());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 94 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class ConfigureSnmpTest method testSplicingSpecificsIntoRanges.

/**
 * Tests getting the correct SNMP Peer after receiving a configureSNMP event that moves a
 * specific from one definition into another.
 *
 * @throws UnknownHostException
 */
public void testSplicingSpecificsIntoRanges() throws UnknownHostException {
    assertEquals(3, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().get(2).getRanges().size());
    assertEquals(6, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().get(2).getSpecifics().size());
    final String specificAddr = "10.1.1.7";
    final EventBuilder bldr = createConfigureSnmpEventBuilder(specificAddr, null);
    final SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent());
    info.setReadCommunityString("splice-test");
    info.setVersion("v2c");
    SnmpPeerFactory.getInstance().define(info);
    assertEquals(5, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().get(2).getRanges().size());
    assertEquals("10.1.1.10", SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().get(2).getSpecifics().get(0));
    assertEquals(1, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().get(2).getSpecifics().size());
    assertEquals(m_startingDefCount, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().size());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 95 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class ConfigureSnmpTest method testCreateSnmpEventInfo.

/**
 * Test method for {@link org.opennms.netmgt.config.SnmpPeerFactory#createSnmpEventInfo(org.opennms.netmgt.xml.event.Event)}.
 * Tests creating an SNMP config definition from a configureSNMP event.
 *
 * @throws UnknownHostException
 */
public void testCreateSnmpEventInfo() throws UnknownHostException {
    EventBuilder bldr = createConfigureSnmpEventBuilder("192.168.1.1", null);
    addCommunityStringToEvent(bldr, "seemore");
    SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent());
    assertNotNull(info);
    assertEquals("192.168.1.1", info.getFirstIPAddress());
    assertNull(info.getLastIPAddress());
    assertTrue(info.isSpecific());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

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