use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class V20191203120602_MigrateSavedSearchesToViews method migrateSavedSearch.
private Map.Entry<View, Search> migrateSavedSearch(SavedSearch savedSearch) {
final String histogramId = randomUUIDProvider.get();
final String messageListId = randomUUIDProvider.get();
final Set<ViewWidget> widgets = ImmutableSet.of(AggregationWidget.create(histogramId), savedSearch.query().toMessagesWidget(messageListId));
final Map<String, Set<String>> widgetMapping = new HashMap<>(widgets.size());
final Set<SearchType> searchTypes = widgets.stream().flatMap(widget -> {
final Set<SearchType> widgetSearchTypes = widget.toSearchTypes(randomUUIDProvider);
widgetMapping.put(widget.id(), widgetSearchTypes.stream().map(SearchType::id).collect(Collectors.toSet()));
return widgetSearchTypes.stream();
}).collect(Collectors.toSet());
final Query.Builder queryBuilder = Query.builder().id(randomUUIDProvider.get()).timerange(savedSearch.query().toTimeRange()).query(savedSearch.query().query()).searchTypes(searchTypes);
final Query query = savedSearch.query().streamId().map(queryBuilder::streamId).orElse(queryBuilder).build();
final Search newSearch = Search.create(randomObjectIdProvider.get(), Collections.singleton(query), savedSearch.creatorUserId(), savedSearch.createdAt());
final Titles titles = Titles.ofWidgetTitles(ImmutableMap.of(histogramId, "Message Count", messageListId, "All Messages"));
final Map<String, ViewWidgetPosition> widgetPositions = ImmutableMap.of(histogramId, ViewWidgetPosition.builder().col(Position.fromInt(1)).row(Position.fromInt(1)).height(Position.fromInt(2)).width(Position.infinity()).build(), messageListId, ViewWidgetPosition.builder().col(Position.fromInt(1)).row(Position.fromInt(3)).height(Position.fromInt(6)).width(Position.infinity()).build());
final ViewState viewState = ViewState.create(titles, widgets, widgetMapping, widgetPositions);
final View newView = View.create(randomObjectIdProvider.get(), "Saved Search: " + savedSearch.title(), "This Search was migrated automatically from the \"" + savedSearch.title() + "\" saved search.", "", newSearch.id(), Collections.singletonMap(query.id(), viewState), Optional.of(savedSearch.creatorUserId()), savedSearch.createdAt());
return new AbstractMap.SimpleEntry<>(newView, newSearch);
}
use of org.graylog2.indexer.messages.Messages 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.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class CmdLineTool method run.
@Override
public void run() {
final Level logLevel = setupLogger();
if (isDumpDefaultConfig()) {
dumpDefaultConfigAndExit();
}
// This is holding all our metrics.
MetricRegistry metricRegistry = MetricRegistryFactory.create();
featureFlags = getFeatureFlags(metricRegistry);
installConfigRepositories();
installCommandConfig();
beforeStart();
beforeStart(parseAndGetTLSConfiguration(), parseAndGetPathConfiguration(configFile));
processConfiguration(jadConfig);
coreConfigInjector = setupCoreConfigInjector();
final Set<Plugin> plugins = loadPlugins(getPluginPath(configFile), chainingClassLoader);
installPluginConfig(plugins);
processConfiguration(jadConfig);
if (isDumpConfig()) {
dumpCurrentConfigAndExit();
}
if (!validateConfiguration()) {
LOG.error("Validating configuration file failed - exiting.");
System.exit(1);
}
final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));
beforeInjectorCreation(plugins);
injector = setupInjector(new NamedConfigParametersModule(jadConfig.getConfigurationBeans()), new PluginBindings(plugins), binder -> binder.bind(MetricRegistry.class).toInstance(metricRegistry));
if (injector == null) {
LOG.error("Injector could not be created, exiting! (Please include the previous error messages in bug " + "reports.)");
System.exit(1);
}
addInstrumentedAppender(metricRegistry, logLevel);
// Report metrics via JMX.
final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).build();
reporter.start();
startCommand();
}
use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class DecoratorProcessorImpl method decorate.
@Override
public SearchResponse decorate(SearchResponse searchResponse, List<SearchResponseDecorator> searchResponseDecorators) {
try {
final Optional<SearchResponseDecorator> metaDecorator = searchResponseDecorators.stream().reduce((f, g) -> (v) -> g.apply(f.apply(v)));
if (metaDecorator.isPresent()) {
final Map<String, ResultMessageSummary> originalMessages = searchResponse.messages().stream().collect(Collectors.toMap(this::getMessageKey, Function.identity()));
final SearchResponse newSearchResponse = metaDecorator.get().apply(searchResponse);
final Set<String> newFields = extractFields(newSearchResponse.messages());
final List<ResultMessageSummary> decoratedMessages = newSearchResponse.messages().stream().map(resultMessage -> {
final ResultMessageSummary originalMessage = originalMessages.get(getMessageKey(resultMessage));
if (originalMessage != null) {
return resultMessage.toBuilder().decorationStats(DecorationStats.create(originalMessage.message(), resultMessage.message())).build();
}
return resultMessage;
}).collect(Collectors.toList());
return newSearchResponse.toBuilder().messages(decoratedMessages).fields(newFields).decorationStats(this.getSearchDecoratorStats(decoratedMessages)).build();
}
} catch (Exception e) {
LOG.error("Error decorating search response", e);
}
return searchResponse;
}
use of org.graylog2.indexer.messages.Messages in project graylog2-server by Graylog2.
the class FixDeflectorByMoveJob method doExecute.
public void doExecute(IndexSet indexSet) {
if (!indexSet.getConfig().isWritable()) {
LOG.debug("No need to fix deflector for non-writable index set <{}> ({})", indexSet.getConfig().id(), indexSet.getConfig().title());
return;
}
if (indexSet.isUp() || !indices.exists(indexSet.getWriteIndexAlias())) {
LOG.error("There is no index <{}>. No need to run this job. Aborting.", indexSet.getWriteIndexAlias());
return;
}
LOG.info("Attempting to fix deflector with move strategy.");
boolean wasProcessing = true;
try {
// Pause message processing and lock the pause.
wasProcessing = serverStatus.isProcessing();
serverStatus.pauseMessageProcessing();
progress = 5;
bufferSynchronizer.waitForEmptyBuffers(EnumSet.of(PROCESS, OUTPUT));
progress = 10;
// Copy messages to new index.
String newTarget = null;
try {
newTarget = indexSet.getNewestIndex();
LOG.info("Starting to move <{}> to <{}>.", indexSet.getWriteIndexAlias(), newTarget);
indices.move(indexSet.getWriteIndexAlias(), newTarget);
} catch (Exception e) {
LOG.error("Moving index failed. Rolling back.", e);
if (newTarget != null) {
indices.delete(newTarget);
}
throw new RuntimeException(e);
}
LOG.info("Done moving deflector index.");
progress = 85;
// Delete deflector index.
LOG.info("Deleting <{}> index.", indexSet.getWriteIndexAlias());
indices.delete(indexSet.getWriteIndexAlias());
progress = 90;
// Set up deflector.
indexSet.setUp();
progress = 95;
} finally {
// Start message processing again.
serverStatus.unlockProcessingPause();
if (wasProcessing) {
serverStatus.resumeMessageProcessing();
}
}
progress = 90;
activityWriter.write(new Activity("Notification condition [" + Notification.Type.DEFLECTOR_EXISTS_AS_INDEX + "] " + "has been fixed.", this.getClass()));
notificationService.fixed(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX);
progress = 100;
LOG.info("Finished.");
}
Aggregations