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