Search in sources :

Example 1 with Message

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

the class FakeHttpRawMessageGenerator method createMessage.

private static Message createMessage(GeneratorState state, int httpCode, Resource resource, int tookMs, DateTime ingestTime) {
    final Message msg = new Message(shortMessage(ingestTime, state.method, state.resource, httpCode, tookMs), state.source, Tools.nowUTC());
    msg.addFields(ingestTimeFields(ingestTime));
    msg.addFields(resourceFields(resource));
    msg.addField("ticks", System.nanoTime());
    msg.addField("http_method", state.method.name());
    msg.addField("http_response_code", httpCode);
    msg.addField("user_id", state.userId);
    msg.addField("took_ms", tookMs);
    return msg;
}
Also used : Message(org.graylog2.plugin.Message)

Example 2 with Message

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

the class BenchmarkOutput method write.

@Override
public void write(List<Message> messages) throws Exception {
    long maxOffset = Long.MIN_VALUE;
    for (final Message message : messages) {
        maxOffset = Math.max(message.getJournalOffset(), maxOffset);
    }
    journal.markJournalOffsetCommitted(maxOffset);
    messagesWritten.mark(messages.size());
}
Also used : Message(org.graylog2.plugin.Message)

Example 3 with Message

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

the class SearchesTest method testTermsStats.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTermsStats() 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(r.getResults()).hasSize(2);
    assertThat(r.getResults().get(0)).hasSize(7).containsEntry("key_field", "ho");
}
Also used : 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 4 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 5 with Message

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

the class KeywordSearchResource method searchKeyword.

@GET
@Timed
@ApiOperation(value = "Message search with keyword as timerange.", notes = "Search for messages in a timerange defined by a keyword like \"yesterday\" or \"2 weeks ago to wednesday\".")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid keyword provided.") })
public SearchResponse searchKeyword(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "keyword", value = "Range keyword", required = true) @QueryParam("keyword") @NotEmpty String keyword, @ApiParam(name = "limit", value = "Maximum number of messages to return.", required = false) @QueryParam("limit") int limit, @ApiParam(name = "offset", value = "Offset", required = false) @QueryParam("offset") int offset, @ApiParam(name = "filter", value = "Filter", required = false) @QueryParam("filter") String filter, @ApiParam(name = "fields", value = "Comma separated list of fields to return", required = false) @QueryParam("fields") String fields, @ApiParam(name = "sort", value = "Sorting (field:asc / field:desc)", required = false) @QueryParam("sort") String sort, @ApiParam(name = "decorate", value = "Run decorators on search result", required = false) @QueryParam("decorate") @DefaultValue("true") boolean decorate) {
    checkSearchPermission(filter, RestPermissions.SEARCHES_KEYWORD);
    final List<String> fieldList = parseOptionalFields(fields);
    final Sorting sorting = buildSorting(sort);
    final TimeRange timeRange = buildKeywordTimeRange(keyword);
    final SearchesConfig searchesConfig = SearchesConfig.builder().query(query).filter(filter).fields(fieldList).range(timeRange).limit(limit).offset(offset).sorting(sorting).build();
    final Optional<String> streamId = Searches.extractStreamId(filter);
    try {
        return buildSearchResponse(searches.search(searchesConfig), timeRange, decorate, streamId);
    } catch (SearchPhaseExecutionException e) {
        throw createRequestExceptionForParseFailure(query, e);
    }
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) SearchesConfig(org.graylog2.indexer.searches.SearchesConfig) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) Sorting(org.graylog2.indexer.searches.Sorting) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Message (org.graylog2.plugin.Message)420 Test (org.junit.Test)391 ApiOperation (io.swagger.annotations.ApiOperation)120 ApiResponses (io.swagger.annotations.ApiResponses)107 Timed (com.codahale.metrics.annotation.Timed)105 RawMessage (org.graylog2.plugin.journal.RawMessage)103 DateTime (org.joda.time.DateTime)102 Path (javax.ws.rs.Path)87 StreamRule (org.graylog2.plugin.streams.StreamRule)77 AuditEvent (org.graylog2.audit.jersey.AuditEvent)69 Produces (javax.ws.rs.Produces)57 Stream (org.graylog2.plugin.streams.Stream)55 CreateMessage (org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage)46 DropMessage (org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage)46 BaseParserTest (org.graylog.plugins.pipelineprocessor.BaseParserTest)45 Rule (org.graylog.plugins.pipelineprocessor.ast.Rule)45 POST (javax.ws.rs.POST)41 GET (javax.ws.rs.GET)40 CloneMessage (org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage)36 MockitoRule (org.mockito.junit.MockitoRule)35