Search in sources :

Example 21 with Message

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

the class SyslogCodecTest method testDecodeStructuredIssue845Empty.

@Test
public void testDecodeStructuredIssue845Empty() throws Exception {
    final Message message = codec.decode(buildRawMessage(STRUCTURED_ISSUE_845_EMPTY));
    assertNotNull(message);
    assertEquals(message.getMessage(), "tralala");
    assertEquals(((DateTime) message.getField("timestamp")).withZone(DateTimeZone.UTC), new DateTime("2015-01-11T15:35:21.335797Z", DateTimeZone.UTC));
    assertEquals(message.getField("source"), "s000000.example.com");
    assertEquals(message.getField("level"), 0);
    assertEquals(message.getField("facility"), "local0");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 22 with Message

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

the class SyslogCodecTest method testIssue3502.

@Test
public void testIssue3502() throws Exception {
    // https://github.com/Graylog2/graylog2-server/issues/3502
    final RawMessage rawMessage = buildRawMessage("<6>0 2017-02-15T16:01:07.000+01:00 hostname test - - -  test 4");
    final Message message = codec.decode(rawMessage);
    assertNotNull(message);
    assertEquals("test 4", message.getMessage());
    assertEquals(new DateTime(2017, 2, 15, 15, 1, 7, DateTimeZone.UTC), message.getTimestamp());
    assertEquals("hostname", message.getSource());
    assertEquals(6, message.getField("level"));
    assertEquals("kernel", message.getField("facility"));
    assertEquals("test", message.getField("application_name"));
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) RawMessage(org.graylog2.plugin.journal.RawMessage) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 23 with Message

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

the class RegexExtractorTest method testExtractsFirstMatcherGroupWhenProvidedWithSeveral.

@Test
public void testExtractsFirstMatcherGroupWhenProvidedWithSeveral() 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 lolwut");
    RegexExtractor x = new RegexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config("id:(\\d+).*(lolwut)"), "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 lolwut", msg.getField("somefield"));
    assertEquals("9001", msg.getField("our_result"));
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 24 with Message

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

the class RegexExtractorTest 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");
    RegexExtractor x = new RegexExtractor(metricRegistry, "foo", "foo", 0, Extractor.CursorStrategy.COPY, "somefield", "our_result", config("id:(\\d+)"), "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 25 with Message

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

the class RegexExtractorTest method testBasicExtractionWithCutStrategyDoesNotLeaveEmptyFields.

@Test
public void testBasicExtractionWithCutStrategyDoesNotLeaveEmptyFields() 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("(.*)"), "foo", noConverters(), Extractor.ConditionType.NONE, null);
    x.runExtractor(msg);
    assertNotNull(msg.getField("our_result"));
    assertEquals("fullyCutByExtractor", 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