Search in sources :

Example 26 with Message

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

Example 27 with Message

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

Example 28 with Message

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

Example 29 with Message

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

Example 30 with Message

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

Aggregations

Test (org.junit.Test)227 Message (org.graylog2.plugin.Message)226 ApiOperation (io.swagger.annotations.ApiOperation)97 ApiResponses (io.swagger.annotations.ApiResponses)91 Timed (com.codahale.metrics.annotation.Timed)90 Path (javax.ws.rs.Path)72 StreamRule (org.graylog2.plugin.streams.StreamRule)70 AuditEvent (org.graylog2.audit.jersey.AuditEvent)62 Produces (javax.ws.rs.Produces)49 DateTime (org.joda.time.DateTime)46 Stream (org.graylog2.plugin.streams.Stream)45 GET (javax.ws.rs.GET)33 RawMessage (org.graylog2.plugin.journal.RawMessage)31 BadRequestException (javax.ws.rs.BadRequestException)30 POST (javax.ws.rs.POST)28 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 PUT (javax.ws.rs.PUT)26 Consumes (javax.ws.rs.Consumes)21 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)21