Search in sources :

Example 36 with Message

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

the class SubstringExtractorTest method testDoesNotRunWhenRegexConditionFails.

@Test
public void testDoesNotRunWhenRegexConditionFails() 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(0, 3), "foo", noConverters(), Extractor.ConditionType.REGEX, "^XXX");
    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 37 with Message

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

the class SubstringExtractorTest method testBasicExtractionDoesNotFailOnNonMatch.

@Test
public void testBasicExtractionDoesNotFailOnNonMatch() 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(100, 200), "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 38 with Message

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

the class SubstringExtractorTest method testBasicExtractionWithCutStrategyCanOverwriteSameField.

@Test
public void testBasicExtractionWithCutStrategyCanOverwriteSameField() throws Exception {
    Message msg = new Message("The short message", "TestUnit", Tools.nowUTC());
    SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "message", "message", config(4, 17), "foo", noConverters(), Extractor.ConditionType.NONE, null);
    x.runExtractor(msg);
    assertEquals("short message", msg.getField("message"));
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 39 with Message

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

the class SubstringExtractorTest method testDoesNotRunWhenStringConditionFails.

@Test
public void testDoesNotRunWhenStringConditionFails() 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(0, 3), "foo", noConverters(), Extractor.ConditionType.STRING, "FOOBAR");
    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 40 with Message

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

the class SubstringExtractorTest 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");
    SubstringExtractor x = new SubstringExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.CUT, "somefield", "our_result", config(100, 200), "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)

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