use of org.opennms.netmgt.config.SyslogdConfig in project opennms by OpenNMS.
the class ConvertToEventTest method testConvertToEvent.
/**
* Test method which calls the ConvertToEvent constructor.
*
* @throws IOException
*/
@Test
public void testConvertToEvent() throws IOException {
InterfaceToNodeCacheDaoImpl.setInstance(new MockInterfaceToNodeCache());
// 10000 sample syslogmessages from xml file are taken and passed as
// Inputstream to create syslogdconfiguration
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-loadtest-configuration.xml");
SyslogdConfig config = new SyslogdConfigFactory(stream);
// Sample message which is embedded in packet and passed as parameter
// to
// ConvertToEvent constructor
byte[] bytes = "<34> 2010-08-19 localhost foo10000: load test 10000 on tty1".getBytes(StandardCharsets.US_ASCII);
// Datagram packet which is passed as parameter for ConvertToEvent
// constructor
DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(), SyslogClient.PORT);
ByteBuffer data = ByteBuffer.wrap(pkt.getData());
// @param len The length of the XML data in the buffer
try {
ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, pkt.getAddress(), pkt.getPort(), data, config);
LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
} catch (MessageDiscardedException e) {
LOG.error("Message Parsing failed", e);
fail("Message Parsing failed: " + e.getMessage());
}
}
use of org.opennms.netmgt.config.SyslogdConfig in project opennms by OpenNMS.
the class ConvertToEventTest method testCiscoEventConversion.
@Test
public void testCiscoEventConversion() throws IOException {
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-cisco-configuration.xml");
SyslogdConfig config = new SyslogdConfigFactory(stream);
try {
ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, InetAddressUtils.ONE_TWENTY_SEVEN, 9999, SyslogdTestUtils.toByteBuffer("<190>Mar 11 08:35:17 aaa_host 30128311: Mar 11 08:35:16.844 CST: %SEC-6-IPACCESSLOGP: list in110 denied tcp 192.168.10.100(63923) -> 192.168.11.128(1521), 1 packet"), config);
LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
} catch (MessageDiscardedException e) {
LOG.error("Message Parsing failed", e);
fail("Message Parsing failed: " + e.getMessage());
}
}
use of org.opennms.netmgt.config.SyslogdConfig in project opennms by OpenNMS.
the class SyslogdReceiverCamelNettyIT method testParallelismAndQueueing.
@Test(timeout = 3 * 60 * 1000)
public void testParallelismAndQueueing() throws UnknownHostException, InterruptedException, ExecutionException {
final int NUM_GENERATORS = 3;
final double MESSAGE_RATE_PER_GENERATOR = 1000.0;
final int NUM_CONSUMER_THREADS = 8;
final int MESSAGE_QUEUE_SIZE = 529;
ThreadLockingDispatcherFactory<SyslogConnection> threadLockingDispatcherFactory = new ThreadLockingDispatcherFactory<>();
ThreadLockingSyncDispatcher<SyslogConnection> syncDispatcher = threadLockingDispatcherFactory.getThreadLockingSyncDispatcher();
CompletableFuture<Integer> future = syncDispatcher.waitForThreads(NUM_CONSUMER_THREADS);
SyslogdConfig syslogdConfig = mock(SyslogdConfig.class);
when(syslogdConfig.getSyslogPort()).thenReturn(SyslogClient.PORT);
when(syslogdConfig.getNumThreads()).thenReturn(NUM_CONSUMER_THREADS);
when(syslogdConfig.getQueueSize()).thenReturn(MESSAGE_QUEUE_SIZE);
DistPollerDao distPollerDao = mock(DistPollerDao.class, Mockito.RETURNS_DEEP_STUBS);
when(distPollerDao.whoami().getId()).thenReturn("");
when(distPollerDao.whoami().getLocation()).thenReturn("");
SyslogReceiverCamelNettyImpl syslogReceiver = new SyslogReceiverCamelNettyImpl(syslogdConfig);
syslogReceiver.setMessageDispatcherFactory(threadLockingDispatcherFactory);
syslogReceiver.setDistPollerDao(distPollerDao);
syslogReceiver.run();
// Fire up the syslog generators
List<SyslogGenerator> generators = new ArrayList<>(NUM_GENERATORS);
for (int k = 0; k < NUM_GENERATORS; k++) {
SyslogGenerator generator = new SyslogGenerator(addr("127.0.0.1"), k, MESSAGE_RATE_PER_GENERATOR);
generator.start();
generators.add(generator);
}
// Wait until we have NUM_CONSUMER_THREADS locked
future.get();
// Now all of the threads are locked, and the queue is full
// Let's continue generating traffic for a few seconds
Thread.sleep(SECONDS.toMillis(10));
// Verify that there aren't more than NUM_CONSUMER_THREADS waiting
assertEquals(0, syncDispatcher.getNumExtraThreadsWaiting());
// Release the producer threads
syncDispatcher.release();
// Stop the receiver
syslogReceiver.stop();
// Stop the generators
for (int k = 0; k < NUM_GENERATORS; k++) {
generators.get(k).stop();
}
}
use of org.opennms.netmgt.config.SyslogdConfig in project opennms by OpenNMS.
the class BufferParserTest method testDifferentImplementations.
@Test
public void testDifferentImplementations() throws Exception {
MockLogAppender.setupLogging(true, "INFO");
final String abc = "<190>Mar 11 08:35:17 127.0.0.1 30128311[4]: Mar 11 08:35:16.844 CST: %SEC-6-IPACCESSLOGP: list in110 denied tcp 192.168.10.100(63923) -> 192.168.11.128(1521), 1 packet";
//String abc = "<190>Mar 11 08:35:17 127.0.0.1 30128311: Mar 11 08:35:16.844 CST: %SEC-6-IPACCESSLOGP: list in110 denied tcp 192.168.10.100(63923) -> 192.168.11.128(1521), 1 packet";
final ByteBuffer incoming = ByteBuffer.wrap(abc.getBytes());
//final List<ParserStage> grokStages = GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}> %{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{NOSPACE:processName}[%{INT:processId}]: %{MONTH:month} %{INT:day} %{STRING:timestamp} %{STRING:timezone} \\%%{STRING:facility}-%{INT:priority}-%{STRING:mnemonic}: %{STRING:message}");
final List<ParserStage> grokStages = GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}> %{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{NOSPACE:processName}[%{INT:processId}]: %{STRING:message}");
//BufferParserFactory grokFactory = parseGrok("<%{INT:facilityPriority}> %{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{NOSPACE:processName}: %{MONTH:month} %{INT:day} %{STRING:timestamp} %{STRING:timezone} \\%%{STRING:facility}-%{INT:priority}-%{STRING:mnemonic}: %{STRING:message}");
final ByteBufferParser<SyslogMessage> grokParser = new SingleSequenceParser(grokStages);
// SyslogNG format
final List<ParserStage> parserStages = new ParserStageSequenceBuilder().intBetweenDelimiters('<', '>', (s, v) -> {
SyslogFacility facility = SyslogFacility.getFacilityForCode(v);
SyslogSeverity priority = SyslogSeverity.getSeverityForCode(v);
s.message.setFacility(facility);
s.message.setSeverity(priority);
}).whitespace().monthString((s, v) -> {
s.message.setMonth(v);
}).whitespace().integer((s, v) -> {
s.message.setDayOfMonth(v);
}).whitespace().integer((s, v) -> {
s.message.setHourOfDay(v);
}).character(':').integer((s, v) -> {
s.message.setMinute(v);
}).character(':').integer((s, v) -> {
s.message.setSecond(v);
}).whitespace().stringUntilWhitespace((s, v) -> {
s.message.setHostName(v);
}).whitespace().stringUntil("\\s[:", (s, v) -> {
s.message.setProcessName(v);
}).optional().character('[').optional().integer((s, v) -> {
s.message.setProcessId(String.valueOf(v));
}).optional().character(']').optional().character(':').whitespace().stringUntilWhitespace(// Original month
null).whitespace().integer(// Original day
null).whitespace().stringUntilWhitespace(// Original timestamp
null).whitespace().stringUntilWhitespace(// Original time zone
null).whitespace().character('%').stringUntilChar('-', null).character('-').stringUntilChar('-', null).character('-').stringUntilChar(':', null).character(':').whitespace().terminal().string((s, v) -> {
s.message.setMessage(v);
}).getStages();
final ByteBufferParser<SyslogMessage> parser = new SingleSequenceParser(parserStages);
final RadixTreeParser radixParser = new RadixTreeParser();
//radixParser.teach(grokStages.toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{INT:version} %{STRING:isotimestamp} %{STRING:hostname} %{STRING:processName} %{STRING:processId} %{STRING:messageId} [%{STRING:structureddata}][%{STRING:structureddata}] %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{INT:version} %{STRING:isotimestamp} %{STRING:hostname} %{STRING:processName} %{STRING:processId} %{STRING:messageId} [%{STRING:structureddata}][%{STRING:structureddata}]").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{INT:version} %{STRING:isotimestamp} %{STRING:hostname} %{STRING:processName} %{STRING:processId} %{STRING:messageId} [%{STRING:structureddata}] %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{INT:version} %{STRING:isotimestamp} %{STRING:hostname} %{STRING:processName} %{STRING:processId} %{STRING:messageId} %{STRING:structureddata} %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{NOSPACE:processName}[%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{NOSPACE:processName}[%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} [%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{NOSPACE:processName}: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} [%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{NOSPACE:processName}: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{STRING:repeatedmonth} %{INT:repeatedday} %{INT:repeatedhour}:%{INT:repeatedminute}:%{INT:repeatedsecond} %{STRING:hostname} %{NOSPACE:processName}[%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{MONTH:month} %{INT:day} %{INT:hour}:%{INT:minute}:%{INT:second} %{STRING:hostname} %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} %{NOSPACE:processName}[%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}> %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} %{NOSPACE:processName}[%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} [%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}> %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} %{NOSPACE:processName}: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}> %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} [%{INT:processId}]: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} %{NOSPACE:processName}: %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}>%{NOSPACE:messageId}: %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} %{STRING:message}").toArray(new ParserStage[0]));
radixParser.teach(GrokParserStageSequenceBuilder.parseGrok("<%{INT:facilityPriority}> %{INT:year}-%{INT:month}-%{INT:day} %{STRING:hostname} %{STRING:message}").toArray(new ParserStage[0]));
final int iterations = 100000;
{
CompletableFuture<SyslogMessage> event = null;
Event lastEvent = null;
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
event = radixParser.parse(incoming.asReadOnlyBuffer());
event.whenComplete((e, ex) -> {
if (ex == null) {
//System.out.println(e.toString());
} else {
ex.printStackTrace();
}
});
}
// Wait for the last future to complete
try {
event.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println("RADIX: " + (end - start) + "ms");
// System.out.println(lastEvent.toString());
}
{
CompletableFuture<SyslogMessage> event = null;
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
event = parser.parse(incoming.asReadOnlyBuffer());
event.whenComplete((e, ex) -> {
if (ex == null) {
//System.out.println(e.toString());
} else {
ex.printStackTrace();
}
});
}
// Wait for the last future to complete
try {
event.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println("NEW: " + (end - start) + "ms");
}
{
CompletableFuture<SyslogMessage> event = null;
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
event = grokParser.parse(incoming.asReadOnlyBuffer());
event.whenComplete((e, ex) -> {
if (ex == null) {
//System.out.println(e.toString());
} else {
ex.printStackTrace();
}
});
}
// Wait for the last future to complete
try {
event.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println("GROK: " + (end - start) + "ms");
}
{
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-syslogng-configuration.xml");
SyslogdConfig config = new SyslogdConfigFactory(stream);
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, InetAddressUtils.ONE_TWENTY_SEVEN, 9999, incoming, config);
Event convertedEvent = convertToEvent.getEvent();
}
long end = System.currentTimeMillis();
System.out.println("OLD: " + (end - start) + "ms");
}
{
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-radix-configuration.xml");
SyslogdConfig config = new SyslogdConfigFactory(stream);
long start = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, InetAddressUtils.ONE_TWENTY_SEVEN, 9999, incoming, config);
Event convertedEvent = convertToEvent.getEvent();
}
long end = System.currentTimeMillis();
System.out.println("RADIX CONVERT: " + (end - start) + "ms");
}
}
use of org.opennms.netmgt.config.SyslogdConfig in project opennms by OpenNMS.
the class ConvertToEventTest method testNms5984.
@Test
public void testNms5984() throws IOException {
InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-nms5984-configuration.xml");
SyslogdConfig config = new SyslogdConfigFactory(stream);
try {
ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, InetAddressUtils.ONE_TWENTY_SEVEN, 9999, SyslogdTestUtils.toByteBuffer("<11>Jul 19 15:55:21 otrs-test OTRS-CGI-76[14364]: [Error][Kernel::System::ImportExport::ObjectBackend::CI2CILink::ImportDataSave][Line:468]: CILink: Could not create link between CIs!"), config);
LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
} catch (MessageDiscardedException e) {
LOG.error("Message Parsing failed", e);
fail("Message Parsing failed: " + e.getMessage());
}
}
Aggregations