use of org.graylog2.gelfclient.GelfMessage in project graylog2-server by Graylog2.
the class GelfOutputTest method testToGELFMessageWithInvalidNumericLevel.
@Test
public void testToGELFMessageWithInvalidNumericLevel() throws Exception {
final GelfTransport transport = mock(GelfTransport.class);
final GelfOutput gelfOutput = new GelfOutput(transport);
final DateTime now = DateTime.now(DateTimeZone.UTC);
final Message message = new Message("Test", "Source", now);
message.addField("level", -1L);
final GelfMessage gelfMessage = gelfOutput.toGELFMessage(message);
assertEquals(GelfMessageLevel.ALERT, gelfMessage.getLevel());
}
use of org.graylog2.gelfclient.GelfMessage in project graylog2-server by Graylog2.
the class GelfOutputTest method testWrite.
@Test
public void testWrite() throws Exception {
final GelfTransport transport = mock(GelfTransport.class);
final Message message = mock(Message.class);
final GelfMessage gelfMessage = new GelfMessage("Test");
final GelfOutput gelfOutput = Mockito.spy(new GelfOutput(transport));
doReturn(gelfMessage).when(gelfOutput).toGELFMessage(message);
gelfOutput.write(message);
verify(transport).send(eq(gelfMessage));
}
use of org.graylog2.gelfclient.GelfMessage in project graylog2-server by Graylog2.
the class GelfOutputTest method testToGELFMessageWithValidStringLevel.
@Test
public void testToGELFMessageWithValidStringLevel() throws Exception {
final GelfTransport transport = mock(GelfTransport.class);
final GelfOutput gelfOutput = new GelfOutput(transport);
final DateTime now = DateTime.now(DateTimeZone.UTC);
final Message message = new Message("Test", "Source", now);
message.addField("level", "6");
final GelfMessage gelfMessage = gelfOutput.toGELFMessage(message);
assertEquals(GelfMessageLevel.INFO, gelfMessage.getLevel());
}
use of org.graylog2.gelfclient.GelfMessage in project graylog2-server by Graylog2.
the class GelfOutputTest method testToGELFMessageWithNullLevel.
@Test
public void testToGELFMessageWithNullLevel() throws Exception {
final GelfTransport transport = mock(GelfTransport.class);
final GelfOutput gelfOutput = new GelfOutput(transport);
final DateTime now = DateTime.now(DateTimeZone.UTC);
final Message message = new Message("Test", "Source", now);
message.addField("level", null);
final GelfMessage gelfMessage = gelfOutput.toGELFMessage(message);
assertEquals(GelfMessageLevel.ALERT, gelfMessage.getLevel());
}
use of org.graylog2.gelfclient.GelfMessage in project graylog2-server by Graylog2.
the class GelfChunkAggregator method addChunk.
@Nonnull
@Override
public Result addChunk(ChannelBuffer buffer) {
final byte[] readable = new byte[buffer.readableBytes()];
buffer.toByteBuffer().get(readable, buffer.readerIndex(), buffer.readableBytes());
final GELFMessage msg = new GELFMessage(readable);
final ChannelBuffer aggregatedBuffer;
switch(msg.getGELFType()) {
case CHUNKED:
try {
chunkCounter.inc();
aggregatedBuffer = checkForCompletion(msg);
if (aggregatedBuffer == null) {
return VALID_EMPTY_RESULT;
}
} catch (IllegalArgumentException | IllegalStateException | IndexOutOfBoundsException e) {
log.debug("Invalid gelf message chunk, dropping message.", e);
return INVALID_RESULT;
}
break;
case ZLIB:
case GZIP:
case UNCOMPRESSED:
aggregatedBuffer = buffer;
break;
case UNSUPPORTED:
return INVALID_RESULT;
default:
return INVALID_RESULT;
}
return new Result(aggregatedBuffer, true);
}
Aggregations