Search in sources :

Example 31 with Version

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

the class GelfCodecTest method decodeSucceedsWithValidTimestampIssue4027.

@Test
public void decodeSucceedsWithValidTimestampIssue4027() 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 32 with Version

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

the class GelfCodecTest method decodeSucceedsWithoutHost.

@Test
public void decodeSucceedsWithoutHost() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"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();
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 33 with Version

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

the class GelfCodecTest method decodeFailsWithBlankMessage.

@Test
public void decodeFailsWithBlankMessage() throws Exception {
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"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 \"message\" field.");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 34 with Version

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

the class SyslogCodecTest method testDecodeUnstructured.

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

Example 35 with Version

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

the class GelfCodecTest method decodeFailsWithEmptyMessage.

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