Search in sources :

Example 26 with Version

use of org.graylog2.plugin.Version 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 27 with Version

use of org.graylog2.plugin.Version 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 28 with Version

use of org.graylog2.plugin.Version 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)

Example 29 with Version

use of org.graylog2.plugin.Version 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 30 with Version

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

the class GelfCodecTest method decodeFailsWithBlankShortMessage.

@Test
public void decodeFailsWithBlankShortMessage() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"short_message\": \"     \"" + "}";
    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 \"short_message\" field.");
}
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