Search in sources :

Example 6 with GELFMessage

use of org.graylog2.inputs.codecs.gelf.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());
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 7 with GELFMessage

use of org.graylog2.inputs.codecs.gelf.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));
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 8 with GELFMessage

use of org.graylog2.inputs.codecs.gelf.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());
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 9 with GELFMessage

use of org.graylog2.inputs.codecs.gelf.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());
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 10 with GELFMessage

use of org.graylog2.inputs.codecs.gelf.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);
}
Also used : GELFMessage(org.graylog2.inputs.codecs.gelf.GELFMessage) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Nonnull(javax.annotation.Nonnull)

Aggregations

Message (org.graylog2.plugin.Message)11 DateTime (org.joda.time.DateTime)11 GelfMessage (org.graylog2.gelfclient.GelfMessage)10 GelfTransport (org.graylog2.gelfclient.transport.GelfTransport)10 Test (org.junit.Test)10 Nullable (javax.annotation.Nullable)2 GELFMessage (org.graylog2.inputs.codecs.gelf.GELFMessage)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 GelfMessageBuilder (org.graylog2.gelfclient.GelfMessageBuilder)1 GelfMessageLevel (org.graylog2.gelfclient.GelfMessageLevel)1 GELFMessageChunk (org.graylog2.inputs.codecs.gelf.GELFMessageChunk)1 RawMessage (org.graylog2.plugin.journal.RawMessage)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1