Bernd Ahlers 2015-01-14 14:04:10 +01:00
parent 6ee6a7f1a1
commit 28a2b817c7

View File

@ -49,6 +49,60 @@ public class StructuredSyslogServerEventTest {
assertEquals(event.getStructuredMessage().getMessage(), "BOMAn application event log entry");
}
@Test
public void testStructured2() throws Exception {
// Message from: https://github.com/Graylog2/graylog2-server/issues/845
final String message = "<190>1 2015-01-06T20:56:33.287Z app-1 app - - [mdc@18060 ip=\"::ffff:132.213.51.30\" logger=\"{c.corp.Handler}\" session=\"4ot7\" user=\"user@example.com\" user-agent=\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11\"] User page 13 requested";
final StructuredSyslogServerEvent event = buildEvent(message);
Map<String, Object> structuredData = new HashMap<String, Object>() {
{
put("mdc@18060", new HashMap<String, String>() {
{
put("ip", "::ffff:132.213.51.30");
put("logger", "{c.corp.Handler}");
put("session", "4ot7");
put("user", "user@example.com");
put("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11");
}
});
}
};
assertEquals(event.getApplicationName(), "app");
assertEquals(event.getDateTime(), new DateTime("2015-01-06T20:56:33.287Z"));
assertEquals(event.getFacility(), 23);
assertEquals(event.getHost(), "app-1");
assertEquals(event.getLevel(), 6);
assertEquals(event.getMessage(), "- [mdc@18060 ip=\"::ffff:132.213.51.30\" logger=\"{c.corp.Handler}\" session=\"4ot7\" user=\"user@example.com\" user-agent=\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11\"] User page 13 requested");
assertEquals(event.getProcessId(), null);
assertEquals(event.getStructuredMessage().getStructuredData(), structuredData);
assertEquals(event.getStructuredMessage().getMessageId(), null);
assertEquals(event.getStructuredMessage().getMessage(), "User page 13 requested");
}
@Test
public void testStructured3() throws Exception {
// Message from: https://github.com/Graylog2/graylog2-server/issues/845
final String message = "<128>1 2015-01-11T16:35:21.335797+01:00 s000000.example.com - - - - tralala";
final StructuredSyslogServerEvent event = buildEvent(message);
assertEquals(event.getApplicationName(), null);
assertEquals(event.getDateTime(), new DateTime("2015-01-11T15:35:21.335797Z"));
assertEquals(event.getFacility(), 16);
assertEquals(event.getHost(), "s000000.example.com");
assertEquals(event.getLevel(), 0);
assertEquals(event.getMessage(), "- - tralala");
assertEquals(event.getProcessId(), null);
assertEquals(event.getStructuredMessage().getStructuredData(), null);
assertEquals(event.getStructuredMessage().getMessageId(), null);
assertEquals(event.getStructuredMessage().getMessage(), "- - tralala");
}
@Test
public void testStructuredWithOnlyStructuredData() throws Exception {
// Message from: https://tools.ietf.org/html/rfc5424#section-6.5