Search in sources :

Example 16 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class MessagesResource method retrieveForSearch.

@ApiOperation(value = "Export a search result as CSV")
@POST
@Path("{searchId}")
@Produces(MoreMediaTypes.TEXT_CSV)
@NoAuditEvent("Has custom audit events")
public ChunkedOutput<SimpleMessageChunk> retrieveForSearch(@ApiParam(value = "ID of an existing Search", name = "searchId") @PathParam("searchId") String searchId, @ApiParam(value = "Optional overrides") @Valid ResultFormat formatFromClient, @Context SearchUser searchUser) {
    ResultFormat format = fillInIfNecessary(emptyIfNull(formatFromClient), searchUser);
    Search search = loadSearch(searchId, format.executionState(), searchUser);
    ExportMessagesCommand command = commandFactory.buildWithSearchOnly(search, format);
    return asyncRunner.apply(chunkConsumer -> exporter(searchId).export(command, chunkConsumer));
}
Also used : Search(org.graylog.plugins.views.search.Search) ResultFormat(org.graylog.plugins.views.search.export.ResultFormat) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 17 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class MessagesResource method retrieveForSearchType.

@ApiOperation(value = "Export a message table as CSV")
@POST
@Path("{searchId}/{searchTypeId}")
@NoAuditEvent("Has custom audit events")
public ChunkedOutput<SimpleMessageChunk> retrieveForSearchType(@ApiParam(value = "ID of an existing Search", name = "searchId") @PathParam("searchId") String searchId, @ApiParam(value = "ID of a Message Table contained in the Search", name = "searchTypeId") @PathParam("searchTypeId") String searchTypeId, @ApiParam(value = "Optional overrides") @Valid ResultFormat formatFromClient, @Context SearchUser searchUser) {
    ResultFormat format = fillInIfNecessary(emptyIfNull(formatFromClient), searchUser);
    Search search = loadSearch(searchId, format.executionState(), searchUser);
    ExportMessagesCommand command = commandFactory.buildWithMessageList(search, searchTypeId, format);
    return asyncRunner.apply(chunkConsumer -> exporter(searchId, searchTypeId).export(command, chunkConsumer));
}
Also used : Search(org.graylog.plugins.views.search.Search) ResultFormat(org.graylog.plugins.views.search.export.ResultFormat) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 18 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class MessagesResource method retrieve.

@ApiOperation(value = "Export messages as CSV", notes = "Use this endpoint, if you want to configure export parameters freely instead of relying on an existing Search")
@POST
@Produces(MoreMediaTypes.TEXT_CSV)
@NoAuditEvent("Has custom audit events")
public ChunkedOutput<SimpleMessageChunk> retrieve(@ApiParam @Valid MessagesRequest rawrequest, @Context SearchUser searchUser) {
    final MessagesRequest request = fillInIfNecessary(rawrequest, searchUser);
    final ValidationRequest.Builder validationReq = ValidationRequest.builder();
    Optional.ofNullable(rawrequest.queryString()).ifPresent(validationReq::query);
    Optional.ofNullable(rawrequest.timeRange()).ifPresent(validationReq::timerange);
    Optional.ofNullable(rawrequest.streams()).ifPresent(validationReq::streams);
    final ValidationResponse validationResponse = queryValidationService.validate(validationReq.build());
    if (validationResponse.status().equals(ValidationStatus.ERROR)) {
        validationResponse.explanations().stream().findFirst().map(ValidationMessage::errorMessage).ifPresent(message -> {
            throw new BadRequestException("Request validation failed: " + message);
        });
    }
    executionGuard.checkUserIsPermittedToSeeStreams(request.streams(), searchUser::canReadStream);
    ExportMessagesCommand command = commandFactory.buildFromRequest(request);
    return asyncRunner.apply(chunkConsumer -> exporter().export(command, chunkConsumer));
}
Also used : ValidationResponse(org.graylog.plugins.views.search.validation.ValidationResponse) ValidationRequest(org.graylog.plugins.views.search.validation.ValidationRequest) MessagesRequest(org.graylog.plugins.views.search.export.MessagesRequest) BadRequestException(javax.ws.rs.BadRequestException) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 19 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class ElasticsearchExportBackendITBase method usesCorrectIndicesAndStreams.

@Test
public void usesCorrectIndicesAndStreams() {
    importFixture("messages.json");
    ExportMessagesCommand command = commandBuilderWithAllStreams().streams(ImmutableSet.of("stream-01", "stream-02")).build();
    mockIndexLookupFor(command, "graylog_0", "graylog_1");
    runWithExpectedResultIgnoringSort(command, "timestamp,source,message", "graylog_0, 2015-01-01T01:00:00.000Z, source-1, Ha", "graylog_1, 2015-01-01T01:59:59.999Z, source-2, He", "graylog_0, 2015-01-01T04:00:00.000Z, source-2, Ho");
}
Also used : ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Test(org.junit.Test) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest)

Example 20 with ExportMessagesCommand

use of org.graylog.plugins.views.search.export.ExportMessagesCommand in project graylog2-server by Graylog2.

the class SearchAfterTest method usesDefaultTieBreakerForNonEventStreams.

@Test
void usesDefaultTieBreakerForNonEventStreams() {
    ExportMessagesCommand command = ExportMessagesCommand.withDefaults().toBuilder().streams("stream-1", "stream-2").build();
    sut.nextChunk(new Search.Builder(""), command);
    List<String> sortKeys = captureSortKeys();
    assertThat(sortKeys).containsExactly(FIELD_TIMESTAMP, DEFAULT_TIEBREAKER_FIELD);
}
Also used : Search(io.searchbox.core.Search) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Test(org.junit.jupiter.api.Test)

Aggregations

ExportMessagesCommand (org.graylog.plugins.views.search.export.ExportMessagesCommand)29 Test (org.junit.Test)23 ElasticsearchBaseTest (org.graylog.testing.elasticsearch.ElasticsearchBaseTest)21 SimpleMessageChunk (org.graylog.plugins.views.search.export.SimpleMessageChunk)9 ApiOperation (io.swagger.annotations.ApiOperation)3 POST (javax.ws.rs.POST)3 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3 Test (org.junit.jupiter.api.Test)3 Search (io.searchbox.core.Search)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Search (org.graylog.plugins.views.search.Search)2 ResultFormat (org.graylog.plugins.views.search.export.ResultFormat)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 BadRequestException (javax.ws.rs.BadRequestException)1