Search in sources :

Example 31 with Message

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

the class SplitAndIndexExtractorTest method testBasicExtraction.

@Test
public void testBasicExtraction() 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");
    SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config(" ", 4), "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", msg.getField("somefield"));
    assertEquals("2013", msg.getField("our_result"));
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 32 with Message

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

the class SplitAndIndexExtractorTest method testBasicExtractionDoesNotFailOnTooHighIndex.

@Test
public void testBasicExtractionDoesNotFailOnTooHighIndex() 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");
    SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config(" ", 9001), "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 33 with Message

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

the class SplitAndIndexExtractorTest method testBasicExtractionDoesNotFailOnNonExistentSplitCharWithCutStrategy.

@Test
public void testBasicExtractionDoesNotFailOnNonExistentSplitCharWithCutStrategy() 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");
    SplitAndIndexExtractor x = new SplitAndIndexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "somefield", "our_result", config("_", 9001), "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 34 with Message

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

the class SubstringExtractorTest method testBasicExtraction.

@Test
public void testBasicExtraction() 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");
    SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config(17, 30), "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", msg.getField("somefield"));
    assertEquals("somesubsystem", msg.getField("our_result"));
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 35 with Message

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

the class SubstringExtractorTest method testDoesNotCutFromStandardFields.

@Test
public void testDoesNotCutFromStandardFields() throws Exception {
    Message msg = new Message("The short message", "TestUnit", Tools.nowUTC());
    SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "message", "our_result", config(0, 3), "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