Search in sources :

Example 11 with Message

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

the class SearchesTest method termsStatsRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void termsStatsRecordsMetrics() throws Exception {
    TermsStatsResult r = searches.termsStats("message", "n", Searches.TermsStatsOrder.COUNT, 25, "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) TermsStatsResult(org.graylog2.indexer.results.TermsStatsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 12 with Message

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

the class SyslogCodecTest method testDecodeStructuredIssue549.

@Test
public void testDecodeStructuredIssue549() throws Exception {
    final Message message = codec.decode(buildRawMessage(STRUCTURED_ISSUE_549));
    assertNotNull(message);
    assertEquals(message.getMessage(), "RT_FLOW_SESSION_DENY [junos@2636.1.1.1.2.39 source-address=\"1.2.3.4\" source-port=\"56639\" destination-address=\"5.6.7.8\" destination-port=\"2003\" service-name=\"None\" protocol-id=\"6\" icmp-type=\"0\" policy-name=\"log-all-else\" source-zone-name=\"campus\" destination-zone-name=\"mngmt\" application=\"UNKNOWN\" nested-application=\"UNKNOWN\" username=\"N/A\" roles=\"N/A\" packet-incoming-interface=\"reth6.0\" encrypted=\"No\"]");
    assertEquals(((DateTime) message.getField("timestamp")).withZone(DateTimeZone.UTC), new DateTime("2014-05-01T08:26:51.179Z", DateTimeZone.UTC));
    assertEquals(message.getField("source-address"), "1.2.3.4");
    assertEquals(message.getField("source-port"), "56639");
    assertEquals(message.getField("destination-address"), "5.6.7.8");
    assertEquals(message.getField("destination-port"), "2003");
    assertEquals(message.getField("service-name"), "None");
    assertEquals(message.getField("protocol-id"), "6");
    assertEquals(message.getField("icmp-type"), "0");
    assertEquals(message.getField("policy-name"), "log-all-else");
    assertEquals(message.getField("source-zone-name"), "campus");
    assertEquals(message.getField("destination-zone-name"), "mngmt");
    assertEquals(message.getField("application"), "UNKNOWN");
    assertEquals(message.getField("nested-application"), "UNKNOWN");
    assertEquals(message.getField("username"), "N/A");
    assertEquals(message.getField("roles"), "N/A");
    assertEquals(message.getField("packet-incoming-interface"), "reth6.0");
    assertEquals(message.getField("encrypted"), "No");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 13 with Message

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

the class SyslogCodecTest method testDecodeUnstructured.

@Test
public void testDecodeUnstructured() throws Exception {
    final Message message = codec.decode(buildRawMessage(UNSTRUCTURED));
    assertNotNull(message);
    assertEquals(message.getMessage(), "c4dc57ba1ebb syslog-ng[7208]: syslog-ng starting up; version='3.5.3'");
    assertEquals(message.getField("timestamp"), new DateTime(YEAR + "-10-21T12:09:37"));
    assertEquals(message.getField("source"), "c4dc57ba1ebb");
    assertEquals(message.getField("level"), 5);
    assertEquals(message.getField("facility"), "syslogd");
    assertNull(message.getField("full_message"));
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 14 with Message

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

the class SyslogCodecTest method rfc3164_section5_4_messages.

@Test
public void rfc3164_section5_4_messages() {
    // See https://tools.ietf.org/html/rfc3164#section-5.4
    final Map<String, Map<String, Object>> rfc3164messages = ImmutableMap.of("<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8", ImmutableMap.of("timestamp", new DateTime(YEAR + "-10-11T22:14:15"), "source", "mymachine", "level", 2, "facility", "security/authorization", "message", "mymachine su: 'su root' failed for lonvick on /dev/pts/8"), "<13>Feb  5 17:32:18 10.0.0.99 Use the BFG!", ImmutableMap.of("timestamp", new DateTime(YEAR + "-02-05T17:32:18"), "source", "10.0.0.99", "level", 5, "facility", "user-level", "message", "10.0.0.99 Use the BFG!"));
    for (Map.Entry<String, Map<String, Object>> entry : rfc3164messages.entrySet()) {
        final Message message = codec.decode(buildRawMessage(entry.getKey()));
        assertThat(message).isNotNull();
        assertThat(message.getFields()).containsAllEntriesOf(entry.getValue());
    }
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with Message

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

the class GelfChunkAggregatorTest method tooManyChunks.

@Test
public void tooManyChunks() {
    final ChannelBuffer[] chunks = createChunkedMessage(129 * 1024, 1024);
    int i = 1;
    for (final ChannelBuffer chunk : chunks) {
        final CodecAggregator.Result result = aggregator.addChunk(chunk);
        if (i == 129) {
            assertFalse("Message invalidated (chunk #" + i + ")", result.isValid());
            assertNull("Message discarded (chunk #" + i + ")", result.getMessage());
        } else {
            assertTrue("Incomplete message valid (chunk #" + i + ")", result.isValid());
            assertNull("Message not complete (chunk #" + i + ")", result.getMessage());
        }
        i++;
    }
}
Also used : CodecAggregator(org.graylog2.plugin.inputs.codecs.CodecAggregator) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) 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