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.");
}
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"));
}
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);
}
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");
}
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");
}
Aggregations