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));
}
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));
}
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));
}
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");
}
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);
}
Aggregations