Search in sources :

Example 16 with RawMessage

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

the class CEFCodecTest method decideSourceWithoutDeviceAddressReturnsCEFHostname.

@Test
public void decideSourceWithoutDeviceAddressReturnsCEFHostname() throws Exception {
    final MappedMessage cefMessage = mock(MappedMessage.class);
    when(cefMessage.host()).thenReturn("128.66.23.42");
    when(cefMessage.mappedExtensions()).thenReturn(Collections.emptyMap());
    final RawMessage rawMessage = new RawMessage(new byte[0], new InetSocketAddress("example.com", 12345));
    assertEquals("128.66.23.42", codec.decideSource(cefMessage, rawMessage));
}
Also used : MappedMessage(org.graylog.plugins.cef.parser.MappedMessage) InetSocketAddress(java.net.InetSocketAddress) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 17 with RawMessage

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

the class CEFCodecTest method decideSourceWithoutDeviceAddressReturnsRawMessageRemoteAddress.

@Test
public void decideSourceWithoutDeviceAddressReturnsRawMessageRemoteAddress() throws Exception {
    final MappedMessage cefMessage = mock(MappedMessage.class);
    when(cefMessage.mappedExtensions()).thenReturn(Collections.emptyMap());
    final RawMessage rawMessage = new RawMessage(new byte[0], new InetSocketAddress("128.66.23.42", 12345));
    // The hostname is unresolved, so we have to add the leading slash. Oh, Java...
    assertEquals("/128.66.23.42", codec.decideSource(cefMessage, rawMessage));
}
Also used : MappedMessage(org.graylog.plugins.cef.parser.MappedMessage) InetSocketAddress(java.net.InetSocketAddress) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 18 with RawMessage

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

the class Beats2CodecTest method messageFromJson.

private RawMessage messageFromJson(String resourceName) throws IOException {
    final URL resource = Resources.getResource(this.getClass(), resourceName);
    final byte[] json = Resources.toByteArray(resource);
    return new RawMessage(json);
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) URL(java.net.URL)

Example 19 with RawMessage

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

the class SyslogCodecTest method testIssue3502.

@Test
public void testIssue3502() throws Exception {
    // https://github.com/Graylog2/graylog2-server/issues/3502
    final RawMessage rawMessage = buildRawMessage("<6>0 2017-02-15T16:01:07.000+01:00 hostname test - - -  test 4");
    final Message message = codec.decode(rawMessage);
    assertNotNull(message);
    assertEquals("test 4", message.getMessage());
    assertEquals(new DateTime(2017, 2, 15, 15, 1, 7, DateTimeZone.UTC), message.getTimestamp());
    assertEquals("hostname", message.getSource());
    assertEquals(6, message.getField("level"));
    assertEquals("kernel", message.getField("facility"));
    assertEquals("test", message.getField("application_name"));
    assertEquals(0, message.getField("facility_num"));
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) RawMessage(org.graylog2.plugin.journal.RawMessage) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 20 with RawMessage

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

the class GelfCodecTest method decodeFailsWithEmptyHost.

@Test
public void decodeFailsWithEmptyHost() 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)

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