Search in sources :

Example 21 with RawMessage

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

the class GelfCodecTest method decodeFailsWithWrongTypeForHost.

@Test
public void decodeFailsWithWrongTypeForHost() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": 42," + "\"short_message\": \"A short message that helps you identify what is going on\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    assertThatIllegalArgumentException().isThrownBy(() -> codec.decode(rawMessage)).withNoCause().withMessageMatching("GELF message <[0-9a-f-]+> has invalid \"host\": 42");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 22 with RawMessage

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

the class GelfCodecTest method decodeSucceedsWithMinimalMessages.

@Test
public void decodeSucceedsWithMinimalMessages() throws Exception {
    assertThat(codec.decode(new RawMessage("{\"short_message\":\"0\"}".getBytes(StandardCharsets.UTF_8)))).isNotNull();
    assertThat(codec.decode(new RawMessage("{\"message\":\"0\"}".getBytes(StandardCharsets.UTF_8)))).isNotNull();
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 23 with RawMessage

use of org.graylog2.plugin.journal.RawMessage 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 24 with RawMessage

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

the class GelfCodecTest method decodeFailsWithBlankHost.

@Test
public void decodeFailsWithBlankHost() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"      \"," + "\"short_message\": \"A short message that helps you identify what is going on\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    assertThatIllegalArgumentException().isThrownBy(() -> codec.decode(rawMessage)).withNoCause().withMessageMatching("GELF message <[0-9a-f-]+> has empty mandatory \"host\" field.");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 25 with RawMessage

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

the class GelfCodecTest method decodeFailsWithoutShortMessage.

@Test
public void decodeFailsWithoutShortMessage() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    assertThatIllegalArgumentException().isThrownBy(() -> codec.decode(rawMessage)).withNoCause().withMessageMatching("GELF message <[0-9a-f-]+> is missing mandatory \"short_message\" or \"message\" field.");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Aggregations

RawMessage (org.graylog2.plugin.journal.RawMessage)59 Test (org.junit.Test)35 Message (org.graylog2.plugin.Message)23 InetSocketAddress (java.net.InetSocketAddress)13 IOException (java.io.IOException)7 Nullable (javax.annotation.Nullable)7 MappedMessage (org.graylog.plugins.cef.parser.MappedMessage)6 ResolvableInetSocketAddress (org.graylog2.plugin.ResolvableInetSocketAddress)6 DateTime (org.joda.time.DateTime)5 Configuration (org.graylog2.plugin.configuration.Configuration)4 ByteBuf (io.netty.buffer.ByteBuf)3 URL (java.net.URL)3 ZonedDateTime (java.time.ZonedDateTime)3 Timer (com.codahale.metrics.Timer)2 List (java.util.List)2 Map (java.util.Map)2 Properties (java.util.Properties)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 NotFoundException (javax.ws.rs.NotFoundException)2 DocumentNotFoundException (org.graylog2.indexer.messages.DocumentNotFoundException)2