Search in sources :

Example 16 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class GelfChunkAggregatorTest method tooManyChunks.

@Test
public void tooManyChunks() {
    final ChannelBuffer[] chunks = createChunkedMessage(129 * 1024, 1024);
    int i = 1;
    for (final ChannelBuffer chunk : chunks) {
        final CodecAggregator.Result result = aggregator.addChunk(chunk);
        if (i == 129) {
            assertFalse("Message invalidated (chunk #" + i + ")", result.isValid());
            assertNull("Message discarded (chunk #" + i + ")", result.getMessage());
        } else {
            assertTrue("Incomplete message valid (chunk #" + i + ")", result.isValid());
            assertNull("Message not complete (chunk #" + i + ")", result.getMessage());
        }
        i++;
    }
}
Also used : CodecAggregator(org.graylog2.plugin.inputs.codecs.CodecAggregator) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 17 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class GelfChunkAggregatorTest method manyChunks.

@Test
public void manyChunks() {
    // creates 5 chunks
    final ChannelBuffer[] chunks = createChunkedMessage(4096 + 512, 1024);
    int i = 0;
    for (final ChannelBuffer chunk : chunks) {
        i++;
        final CodecAggregator.Result result = aggregator.addChunk(chunk);
        assertTrue(result.isValid());
        if (i == 5) {
            assertNotNull("message should've been assembled from chunks", result.getMessage());
            assertEquals(1, counterValueNamed(metricRegistry, COMPLETE_MESSAGES));
            assertEquals(5, counterValueNamed(metricRegistry, CHUNK_COUNTER));
            assertEquals(0, counterValueNamed(metricRegistry, WAITING_MESSAGES));
            assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_CHUNKS));
            assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_MESSAGES));
            assertEquals(0, counterValueNamed(metricRegistry, DUPLICATE_CHUNKS));
        } else {
            assertNull("chunks not complete", result.getMessage());
            assertEquals("message not complete yet", 0, counterValueNamed(metricRegistry, COMPLETE_MESSAGES));
            assertEquals(i, counterValueNamed(metricRegistry, CHUNK_COUNTER));
            assertEquals("one message waiting", 1, counterValueNamed(metricRegistry, WAITING_MESSAGES));
            assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_CHUNKS));
            assertEquals(0, counterValueNamed(metricRegistry, EXPIRED_MESSAGES));
            assertEquals(0, counterValueNamed(metricRegistry, DUPLICATE_CHUNKS));
        }
    }
}
Also used : CodecAggregator(org.graylog2.plugin.inputs.codecs.CodecAggregator) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 18 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class GelfCodecTest method decodeBuildsValidMessageObject.

@Test
public void decodeBuildsValidMessageObject() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"short_message\": \"A short message that helps you identify what is going on\"," + "\"full_message\": \"Backtrace here\\n\\nMore stuff\"," + "\"timestamp\": 1385053862.3072," + "\"level\": 1," + "\"_user_id\": 9001," + "\"_some_info\": \"foo\"," + "\"_some_env_var\": \"bar\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    final Message message = codec.decode(rawMessage);
    assertThat(message).isNotNull();
    assertThat(message.getField("source")).isEqualTo("example.org");
    assertThat(message.getField("message")).isEqualTo("A short message that helps you identify what is going on");
    assertThat(message.getField("user_id")).isEqualTo(9001L);
    assertThat(message.getFieldNames()).containsOnly("_id", "source", "message", "full_message", "timestamp", "level", "user_id", "some_info", "some_env_var");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 19 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class GelfCodecTest method decodeFiltersOutVersionField.

@Test
public void decodeFiltersOutVersionField() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"short_message\": \"A short message that helps you identify what is going on\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    final Message message = codec.decode(rawMessage);
    assertThat(message).isNotNull();
    assertThat(message.getField("version")).isNull();
    assertThat(message.getField("source")).isEqualTo("example.org");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 20 with Message

use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.

the class SyslogCodecTest method testDecodeUnstructuredWithFullMessage.

@Test
public void testDecodeUnstructuredWithFullMessage() throws Exception {
    when(configuration.getBoolean(SyslogCodec.CK_STORE_FULL_MESSAGE)).thenReturn(true);
    final Message message = codec.decode(buildRawMessage(UNSTRUCTURED));
    assertNotNull(message);
    assertEquals(message.getMessage(), "c4dc57ba1ebb syslog-ng[7208]: syslog-ng starting up; version='3.5.3'");
    assertEquals(message.getField("timestamp"), new DateTime(YEAR + "-10-21T12:09:37"));
    assertEquals(message.getField("source"), "c4dc57ba1ebb");
    assertEquals(message.getField("level"), 5);
    assertEquals(message.getField("facility"), "syslogd");
    assertEquals(message.getField("full_message"), UNSTRUCTURED);
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)227 Message (org.graylog2.plugin.Message)226 ApiOperation (io.swagger.annotations.ApiOperation)97 ApiResponses (io.swagger.annotations.ApiResponses)91 Timed (com.codahale.metrics.annotation.Timed)90 Path (javax.ws.rs.Path)72 StreamRule (org.graylog2.plugin.streams.StreamRule)70 AuditEvent (org.graylog2.audit.jersey.AuditEvent)62 Produces (javax.ws.rs.Produces)49 DateTime (org.joda.time.DateTime)46 Stream (org.graylog2.plugin.streams.Stream)45 GET (javax.ws.rs.GET)33 RawMessage (org.graylog2.plugin.journal.RawMessage)31 BadRequestException (javax.ws.rs.BadRequestException)30 POST (javax.ws.rs.POST)28 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 PUT (javax.ws.rs.PUT)26 Consumes (javax.ws.rs.Consumes)21 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)21