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();
}
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);
}
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());
}
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());
}
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());
}
Aggregations