use of org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO in project opennms by OpenNMS.
the class SyslogdLoadIT method testNGSyslog.
@Test
@Transactional
public void testNGSyslog() throws Exception {
loadSyslogConfiguration("/etc/syslogd-syslogng-configuration.xml");
startSyslogdJavaNet();
m_eventCounter.anticipate();
InetAddress address = InetAddress.getLocalHost();
// handle an invalid packet
byte[] bytes = "<34>main: 2010-08-19 localhost foo0: 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>monkeysatemybrain!\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.SyslogMessageLogDTO in project opennms by OpenNMS.
the class SyslogSinkModule method getAggregationPolicy.
@Override
public AggregationPolicy<SyslogConnection, SyslogMessageLogDTO, SyslogMessageLogDTO> getAggregationPolicy() {
final String systemId = distPollerDao.whoami().getId();
final String systemLocation = distPollerDao.whoami().getLocation();
return new AggregationPolicy<SyslogConnection, SyslogMessageLogDTO, SyslogMessageLogDTO>() {
@Override
public int getCompletionSize() {
return config.getBatchSize();
}
@Override
public int getCompletionIntervalMs() {
return config.getBatchIntervalMs();
}
@Override
public Object key(SyslogConnection syslogConnection) {
return syslogConnection.getSource();
}
@Override
public SyslogMessageLogDTO aggregate(SyslogMessageLogDTO accumulator, SyslogConnection connection) {
if (accumulator == null) {
accumulator = new SyslogMessageLogDTO(systemLocation, systemId, connection.getSource());
}
SyslogMessageDTO messageDTO = new SyslogMessageDTO(connection.getBuffer());
accumulator.getMessages().add(messageDTO);
return accumulator;
}
@Override
public SyslogMessageLogDTO build(SyslogMessageLogDTO accumulator) {
return accumulator;
}
};
}
use of org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO 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.syslogd.api.SyslogMessageLogDTO 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.SyslogMessageLogDTO 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());
}
Aggregations