use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RegexExtractorTest method testBasicExtractionDoesNotFailOnNonMatchWithCutStrategy.
@Test
public void testBasicExtractionDoesNotFailOnNonMatchWithCutStrategy() 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("nothing:(\\d+)"), "foo", noConverters(), Extractor.ConditionType.NONE, null);
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 RegexReplaceExtractorTest method testReplacementWithReplaceAll.
@Test
public void testReplacementWithReplaceAll() throws Exception {
final Message message = new Message("Foobar 123 Foobaz 456", "source", Tools.nowUTC());
final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "(\\w+) (\\d+)", "replacement", "$2/$1", "replace_all", true), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
extractor.runExtractor(message);
assertThat(message.getMessage()).isEqualTo("123/Foobar 456/Foobaz");
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RegexReplaceExtractorTest method testReplacementWithNoMatchAndDefaultReplacement.
@Test
public void testReplacementWithNoMatchAndDefaultReplacement() throws Exception {
final Message message = new Message("Test", "source", Tools.nowUTC());
final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "NO-MATCH"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
extractor.runExtractor(message);
assertThat(message.getMessage()).isEqualTo("Test");
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RegexReplaceExtractorTest method testReplacementWithOnePlaceholder.
@Test
public void testReplacementWithOnePlaceholder() throws Exception {
final Message message = new Message("Test Foobar", "source", Tools.nowUTC());
final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "Test (\\w+)"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
extractor.runExtractor(message);
assertThat(message.getMessage()).isEqualTo("Foobar");
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class SplitAndIndexExtractorTest method testDoesNotCutFromStandardFields.
@Test
public void testDoesNotCutFromStandardFields() throws Exception {
Message msg = new Message("The short message", "TestUnit", Tools.nowUTC());
SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "message", "our_result", config(" ", 1), "foo", noConverters(), Extractor.ConditionType.NONE, null);
x.runExtractor(msg);
// Would be cut to "short message" if cutting from standard field was allowed.
assertEquals("The short message", msg.getField("message"));
}
Aggregations