use of org.opennms.netmgt.syslogd.api.SyslogConnection in project opennms by OpenNMS.
the class SyslogSinkConsumerNewSuspectIT method testSyncWithDatabaseThenClear.
@Test
@Transactional
public void testSyncWithDatabaseThenClear() 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);
// Sync the cache with the database
m_cache.dataSourceSync();
// The cache has entries from the database
assertTrue(0 < m_cache.size());
// Create a new SyslogConnection and call it to create the processed event
Event e = dispatchAndCapture(new SyslogConnection(pkt, false));
// The node is in the database so it should already be in the cache
Long foundid = e.getNodeid();
LOG.debug("Found node ID: {}", foundid);
assertEquals("Node ID was not present: " + e.getNodeid(), Long.valueOf(nodeId.longValue()), foundid);
// Clear the cache
m_cache.clear();
assertEquals(0, m_cache.size());
// Create a new SyslogConnection and call it to create the processed event
e = dispatchAndCapture(new SyslogConnection(pkt, false));
// The node is in the database so it should already be in the cache
foundid = e.getNodeid();
LOG.debug("Found node ID: {}", foundid);
assertTrue("Node ID was unexpectedly present: " + e.getNodeid(), foundid < 1);
}
use of org.opennms.netmgt.syslogd.api.SyslogConnection in project opennms by OpenNMS.
the class SyslogdEventdLoadIT method testDefaultSyslogd.
@Test(timeout = 120000)
@Transactional
public void testDefaultSyslogd() throws Exception {
startSyslogdGracefully();
int eventCount = 100;
List<Integer> foos = new ArrayList<>();
for (int i = 0; i < eventCount; i++) {
int eventNum = Double.valueOf(Math.random() * 10000).intValue();
foos.add(eventNum);
}
m_eventCounter.setAnticipated(eventCount);
long start = System.currentTimeMillis();
String testPduFormat = "2010-08-19 localhost foo%d: load test %d on tty1";
SyslogClient sc = new SyslogClient(null, 10, SyslogClient.LOG_DEBUG, addr("127.0.0.1"));
for (int i = 0; i < eventCount; i++) {
int foo = foos.get(i);
DatagramPacket pkt = sc.getPacket(SyslogClient.LOG_DEBUG, String.format(testPduFormat, foo, foo));
SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
m_syslogSinkConsumer.handleMessage(messageLog);
}
long mid = System.currentTimeMillis();
m_eventCounter.waitForFinish(120000);
long end = System.currentTimeMillis();
final long total = (end - start);
final double eventsPerSecond = (eventCount * 1000.0 / total);
System.err.println(String.format("total time: %d, wait time: %d, events per second: %8.4f", total, (end - mid), eventsPerSecond));
}
use of org.opennms.netmgt.syslogd.api.SyslogConnection in project opennms by OpenNMS.
the class SyslogdEventdLoadIT method testRfcSyslog.
@Test(timeout = 120000)
@Transactional
public void testRfcSyslog() throws Exception {
loadSyslogConfiguration("/etc/syslogd-rfc-configuration.xml");
startSyslogdGracefully();
m_eventCounter.anticipate();
InetAddress address = InetAddress.getLocalHost();
// handle an invalid packet
byte[] bytes = "<34>1 2010-08-19T22:14:15.000Z localhost - - - - \uFEFFfoo0: load test 0 on tty1\0".getBytes(StandardCharsets.UTF_8);
DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
m_syslogSinkConsumer.handleMessage(messageLog);
// handle a valid packet
bytes = "<34>1 2003-10-11T22:14:15.000Z plonk -ev/pts/8\0".getBytes();
pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
m_syslogSinkConsumer.handleMessage(messageLog);
m_eventCounter.waitForFinish(120000);
assertEquals(1, m_eventCounter.getCount());
}
use of org.opennms.netmgt.syslogd.api.SyslogConnection in project opennms by OpenNMS.
the class SyslogdLoadIT method testSyslogConnectionHandlerDefaultImpl.
@Test
@Transactional
public void testSyslogConnectionHandlerDefaultImpl() throws Exception {
final int eventCount = 100;
List<Integer> foos = new ArrayList<>();
for (int i = 0; i < eventCount; i++) {
int eventNum = Double.valueOf(Math.random() * 10000).intValue();
foos.add(eventNum);
}
m_eventCounter.setAnticipated(eventCount);
String testPduFormat = "2010-08-19 localhost foo%d: load test %d on tty1";
SyslogClient sc = new SyslogClient(null, 10, SyslogClient.LOG_USER, addr("127.0.0.1"));
// Test by directly invoking the SyslogConnection task
System.err.println("Starting to send packets");
final long start = System.currentTimeMillis();
for (int i = 0; i < eventCount; i++) {
int foo = foos.get(i);
DatagramPacket pkt = sc.getPacket(SyslogClient.LOG_DEBUG, String.format(testPduFormat, foo, foo));
SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
m_syslogSinkConsumer.handleMessage(messageLog);
}
long mid = System.currentTimeMillis();
System.err.println(String.format("Sent %d packets in %d milliseconds", eventCount, mid - start));
m_eventCounter.waitForFinish(60000);
long end = System.currentTimeMillis();
System.err.println(String.format("Events expected: %d, events received: %d", eventCount, m_eventCounter.getCount()));
final long total = (end - start);
final double eventsPerSecond = (eventCount * 1000.0 / total);
System.err.println(String.format("total time: %d, wait time: %d, events per second: %8.4f", total, (end - mid), eventsPerSecond));
assertEquals(eventCount, m_eventCounter.getCount());
}
use of org.opennms.netmgt.syslogd.api.SyslogConnection in project opennms by OpenNMS.
the class SyslogdLoadIT method testRfcSyslog.
@Test
@Transactional
public void testRfcSyslog() throws Exception {
loadSyslogConfiguration("/etc/syslogd-rfc-configuration.xml");
startSyslogdJavaNet();
m_eventCounter.anticipate();
InetAddress address = InetAddress.getLocalHost();
// handle an invalid packet
byte[] bytes = "<34>1 2010-08-19T22:14:15.000Z localhost - - - - \uFEFFfoo0: load test 0 on tty1\0".getBytes();
DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
SyslogMessageLogDTO messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
m_syslogSinkConsumer.handleMessage(messageLog);
// handle a valid packet
bytes = "<34>1 2003-10-11T22:14:15.000Z plonk -ev/pts/8\0".getBytes();
pkt = new DatagramPacket(bytes, bytes.length, address, SyslogClient.PORT);
messageLog = m_syslogSinkModule.toMessageLog(new SyslogConnection(pkt, false));
m_syslogSinkConsumer.handleMessage(messageLog);
m_eventCounter.waitForFinish(120000);
assertEquals(1, m_eventCounter.getCount());
}
Aggregations