Search in sources :

Example 6 with RegexReplaceExtractor

use of org.graylog2.inputs.extractors.RegexReplaceExtractor in project graylog2-server by Graylog2.

the class RegexReplaceExtractorTest method testReplacementWithTooManyPlaceholders.

@Test(expected = RuntimeException.class)
public void testReplacementWithTooManyPlaceholders() throws Exception {
    final Message message = new Message("Foobar 123", "source", Tools.nowUTC());
    final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "Foobar (\\d+)", "replacement", "$1 $2"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
    extractor.runExtractor(message);
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 7 with RegexReplaceExtractor

use of org.graylog2.inputs.extractors.RegexReplaceExtractor in project graylog2-server by Graylog2.

the class RegexReplaceExtractorTest method testReplacementWithCustomReplacement.

@Test
public void testReplacementWithCustomReplacement() throws Exception {
    final Message message = new Message("Foobar 123", "source", Tools.nowUTC());
    final RegexReplaceExtractor extractor = new RegexReplaceExtractor(metricRegistry, "id", "title", 0L, Extractor.CursorStrategy.COPY, "message", "message", ImmutableMap.<String, Object>of("regex", "(Foobar) (\\d+)", "replacement", "$2/$1"), "user", Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, null);
    extractor.runExtractor(message);
    assertThat(message.getMessage()).isEqualTo("123/Foobar");
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Aggregations

Message (org.graylog2.plugin.Message)6 Test (org.junit.Test)6 MetricRegistry (com.codahale.metrics.MetricRegistry)1 BadRequestException (javax.ws.rs.BadRequestException)1 ConfigurationException (org.graylog2.ConfigurationException)1 RegexReplaceExtractor (org.graylog2.inputs.extractors.RegexReplaceExtractor)1 Converter (org.graylog2.plugin.inputs.Converter)1 Extractor (org.graylog2.plugin.inputs.Extractor)1 RegexReplaceTesterResponse (org.graylog2.rest.models.tools.responses.RegexReplaceTesterResponse)1