use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class SyslogCodecTest method testDecodeStructuredIssue845Empty.
@Test
public void testDecodeStructuredIssue845Empty() throws Exception {
final Message message = codec.decode(buildRawMessage(STRUCTURED_ISSUE_845_EMPTY));
assertNotNull(message);
assertEquals(message.getMessage(), "tralala");
assertEquals(((DateTime) message.getField("timestamp")).withZone(DateTimeZone.UTC), new DateTime("2015-01-11T15:35:21.335797Z", DateTimeZone.UTC));
assertEquals(message.getField("source"), "s000000.example.com");
assertEquals(message.getField("level"), 0);
assertEquals(message.getField("facility"), "local0");
}
use of org.graylog2.plugin.Message 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"));
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RegexExtractorTest method testExtractsFirstMatcherGroupWhenProvidedWithSeveral.
@Test
public void testExtractsFirstMatcherGroupWhenProvidedWithSeveral() throws Exception {
Message msg = new Message("The short message", "TestUnit", Tools.nowUTC());
msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001 lolwut");
RegexExtractor x = new RegexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config("id:(\\d+).*(lolwut)"), "foo", noConverters(), Extractor.ConditionType.NONE, null);
x.runExtractor(msg);
assertNotNull(msg.getField("our_result"));
assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001 lolwut", msg.getField("somefield"));
assertEquals("9001", msg.getField("our_result"));
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RegexExtractorTest method testDoesNotRunWhenRegexConditionFails.
@Test
public void testDoesNotRunWhenRegexConditionFails() throws Exception {
Message msg = new Message("The short message", "TestUnit", Tools.nowUTC());
msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001");
RegexExtractor x = new RegexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config("id:(\\d+)"), "foo", noConverters(), Extractor.ConditionType.REGEX, "^XXX");
x.runExtractor(msg);
assertNull(msg.getField("our_result"));
assertEquals("<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001", msg.getField("somefield"));
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RegexExtractorTest method testBasicExtractionWithCutStrategyDoesNotLeaveEmptyFields.
@Test
public void testBasicExtractionWithCutStrategyDoesNotLeaveEmptyFields() throws Exception {
Message msg = new Message("The short message", "TestUnit", Tools.nowUTC());
msg.addField("somefield", "<10> 07 Aug 2013 somesubsystem: this is my message for username9001 id:9001");
RegexExtractor x = new RegexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "somefield", "our_result", config("(.*)"), "foo", noConverters(), Extractor.ConditionType.NONE, null);
x.runExtractor(msg);
assertNotNull(msg.getField("our_result"));
assertEquals("fullyCutByExtractor", msg.getField("somefield"));
}
Aggregations