Search in sources :

Example 6 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class SyslogPriLevelConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    Converter hc = new SyslogPriLevelConverter(new HashMap<String, Object>());
    assertNull(hc.convert(null));
    assertEquals("", hc.convert(""));
    assertEquals("lol no number", hc.convert("lol no number"));
    // info
    assertEquals(6, hc.convert("14"));
    // warning
    assertEquals(4, hc.convert("12"));
    // debug
    assertEquals(7, hc.convert("7"));
    // debug
    assertEquals(7, hc.convert("87"));
    // notice
    assertEquals(5, hc.convert("5"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) Test(org.junit.Test)

Example 7 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class TokenizerConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    Converter hc = new TokenizerConverter(new HashMap<String, Object>());
    assertNull(hc.convert(null));
    assertEquals("", hc.convert(""));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) Test(org.junit.Test)

Example 8 with Converter

use of org.graylog2.plugin.inputs.Converter in project graylog2-server by Graylog2.

the class UppercaseConverterTest method testConvert.

@Test
public void testConvert() throws Exception {
    Converter c = new UppercaseConverter(new HashMap<String, Object>());
    assertNull(c.convert(null));
    assertEquals("", c.convert(""));
    assertEquals("FOOBAR", c.convert("foobar"));
    assertEquals("FOO BAR", c.convert("foo BAR"));
    assertEquals("FOOBAR", c.convert("FooBar"));
    assertEquals("FOOBAR ", c.convert("foobar "));
    assertEquals(" FOOBAR", c.convert(" foobar"));
    assertEquals("FOOBAR", c.convert("FOOBAR"));
}
Also used : Converter(org.graylog2.plugin.inputs.Converter) Test(org.junit.Test)

Example 9 with Converter

use of org.graylog2.plugin.inputs.Converter 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");
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 10 with Converter

use of org.graylog2.plugin.inputs.Converter 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");
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 Converter (org.graylog2.plugin.inputs.Converter)22 Message (org.graylog2.plugin.Message)14 DateTime (org.joda.time.DateTime)10 Function (com.google.common.base.Function)8 Result (org.graylog2.plugin.inputs.Extractor.Result)8 Callable (java.util.concurrent.Callable)7 MetricRegistry (com.codahale.metrics.MetricRegistry)6 Extractor (org.graylog2.plugin.inputs.Extractor)6 BadRequestException (javax.ws.rs.BadRequestException)2 ConfigurationException (org.graylog2.ConfigurationException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BasicDBList (com.mongodb.BasicDBList)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NotFoundException (org.graylog2.database.NotFoundException)1 ConverterFactory (org.graylog2.inputs.converters.ConverterFactory)1