Search in sources :

Example 41 with Version

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

the class GelfCodecTest method decodeIncludesSourceAddressIfItFails.

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

Example 42 with Version

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

the class GelfCodecTest method decodeSucceedsWithValidTimestampAsStringIssue4027.

@Test
public void decodeSucceedsWithValidTimestampAsStringIssue4027() throws Exception {
    // https://github.com/Graylog2/graylog2-server/issues/4027
    final String json = "{" + "\"version\": \"1.1\"," + "\"short_message\": \"A short message that helps you identify what is going on\"," + "\"host\": \"example.org\"," + "\"timestamp\": \"1500646980.661\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    final Message message = codec.decode(rawMessage);
    assertThat(message).isNotNull();
    assertThat(message.getTimestamp()).isEqualTo(DateTime.parse("2017-07-21T14:23:00.661Z"));
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 43 with Version

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

the class GelfCodecTest method decodeLargeCompressedMessageFails.

@Test
public void decodeLargeCompressedMessageFails() throws Exception {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("JSON is null/could not be parsed (invalid JSON)");
    expectedException.expectCause(isA(JsonParseException.class));
    final Configuration configuration = new Configuration(Collections.singletonMap("decompress_size_limit", 100));
    final GelfCodec codec = new GelfCodec(configuration, aggregator);
    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," + "\"_some_bytes1\": \"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, \"," + "\"_some_bytes2\": \"sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, \"," + "\"_some_bytes2\": \"sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.\"" + "}";
    final byte[] payload = TestHelper.zlibCompress(json);
    assumeTrue(payload.length > 100);
    final RawMessage rawMessage = new RawMessage(payload);
    codec.decode(rawMessage);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 44 with Version

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

the class GelfCodecTest method decodeAllowsSettingCustomVersionField.

@Test
public void decodeAllowsSettingCustomVersionField() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"short_message\": \"A short message that helps you identify what is going on\"," + "\"_version\": \"3.11\"" + "}";
    final RawMessage rawMessage = new RawMessage(json.getBytes(StandardCharsets.UTF_8));
    final Message message = codec.decode(rawMessage);
    assertThat(message).isNotNull();
    assertThat(message.getField("version")).isEqualTo("3.11");
    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 45 with Version

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

the class GelfCodecTest method decodeFailsWithWrongTypeForShortMessage.

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

Aggregations

Test (org.junit.Test)29 RawMessage (org.graylog2.plugin.journal.RawMessage)28 Message (org.graylog2.plugin.Message)15 SearchVersion (org.graylog2.storage.SearchVersion)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 IOException (java.io.IOException)5 Inject (javax.inject.Inject)5 DateTime (org.joda.time.DateTime)5 ZonedDateTime (java.time.ZonedDateTime)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)4 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)4 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ApiOperation (io.swagger.annotations.ApiOperation)3 URI (java.net.URI)3 HashSet (java.util.HashSet)3