use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class AbsoluteSearchResource method searchAbsoluteChunked.
@GET
@Timed
@ApiOperation(value = "Message search with absolute timerange.", notes = "Search for messages using an absolute timerange, specified as from/to " + "with format yyyy-MM-ddTHH:mm:ss.SSSZ (e.g. 2014-01-23T15:34:49.000Z) or yyyy-MM-dd HH:mm:ss.")
@Produces(MoreMediaTypes.TEXT_CSV)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid timerange parameters provided.") })
public ChunkedOutput<ScrollResult.ScrollChunk> searchAbsoluteChunked(@ApiParam(name = "query", value = "Query (Lucene syntax)", required = true) @QueryParam("query") @NotEmpty String query, @ApiParam(name = "from", value = "Timerange start. See description for date format", required = true) @QueryParam("from") String from, @ApiParam(name = "to", value = "Timerange end. See description for date format", required = true) @QueryParam("to") String to, @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 = true) @QueryParam("fields") String fields) {
checkSearchPermission(filter, RestPermissions.SEARCHES_ABSOLUTE);
final List<String> fieldList = parseFields(fields);
final TimeRange timeRange = buildAbsoluteTimeRange(from, to);
try {
final ScrollResult scroll = searches.scroll(query, timeRange, limit, offset, fieldList, filter);
return buildChunkedOutput(scroll, limit);
} catch (SearchPhaseExecutionException e) {
throw createRequestExceptionForParseFailure(query, e);
}
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class ClusterSystemShutdownResource method shutdown.
@POST
@Timed
@ApiOperation(value = "Shutdown node gracefully.", notes = "Attempts to process all buffered and cached messages before exiting, " + "shuts down inputs first to make sure that no new messages are accepted.")
@AuditEvent(type = AuditEventTypes.NODE_SHUTDOWN_INITIATE)
public void shutdown(@ApiParam(name = "nodeId", value = "The id of the node to shutdown.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
final Node targetNode = nodeService.byNodeId(nodeId);
RemoteSystemShutdownResource remoteSystemShutdownResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemShutdownResource.class);
final Response response = remoteSystemShutdownResource.shutdown().execute();
if (response.code() != ACCEPTED.getCode()) {
LOG.warn("Unable send shut down signal to node {}: {}", nodeId, response.message());
throw new WebApplicationException(response.message(), BAD_GATEWAY);
}
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class DecodingProcessor method processMessage.
private void processMessage(final MessageEvent event) throws ExecutionException {
final RawMessage raw = event.getRaw();
// for backwards compatibility: the last source node should contain the input we use.
// this means that extractors etc defined on the prior inputs are silently ignored.
// TODO fix the above
String inputIdOnCurrentNode;
try {
// .inputId checked during raw message decode!
inputIdOnCurrentNode = Iterables.getLast(raw.getSourceNodes()).inputId;
} catch (NoSuchElementException e) {
inputIdOnCurrentNode = null;
}
final Codec.Factory<? extends Codec> factory = codecFactory.get(raw.getCodecName());
if (factory == null) {
LOG.warn("Couldn't find factory for codec <{}>, skipping message {} on input <{}>.", raw.getCodecName(), raw, inputIdOnCurrentNode);
return;
}
final Codec codec = factory.create(raw.getCodecConfig());
final String baseMetricName = name(codec.getClass(), inputIdOnCurrentNode);
Message message = null;
Collection<Message> messages = null;
final Timer.Context decodeTimeCtx = parseTime.time();
final long decodeTime;
try {
// TODO The Codec interface should be changed for 2.0 to support collections of messages so we can remove this hack.
if (codec instanceof MultiMessageCodec) {
messages = ((MultiMessageCodec) codec).decodeMessages(raw);
} else {
message = codec.decode(raw);
}
} catch (RuntimeException e) {
LOG.error("Unable to decode raw message {} on input <{}>.", raw, inputIdOnCurrentNode);
metricRegistry.meter(name(baseMetricName, "failures")).mark();
throw e;
} finally {
decodeTime = decodeTimeCtx.stop();
}
if (message != null) {
event.setMessage(postProcessMessage(raw, codec, inputIdOnCurrentNode, baseMetricName, message, decodeTime));
} else if (messages != null && !messages.isEmpty()) {
final List<Message> processedMessages = Lists.newArrayListWithCapacity(messages.size());
for (final Message msg : messages) {
final Message processedMessage = postProcessMessage(raw, codec, inputIdOnCurrentNode, baseMetricName, msg, decodeTime);
if (processedMessage != null) {
processedMessages.add(processedMessage);
}
}
event.setMessages(processedMessages);
}
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class ProcessBufferProcessor method handleMessage.
private void handleMessage(@Nonnull Message msg) {
msg.addStream(defaultStreamProvider.get());
Messages messages = msg;
for (MessageProcessor messageProcessor : orderedMessageProcessors) {
messages = messageProcessor.process(messages);
}
for (Message message : messages) {
outputBuffer.insertBlocking(message);
}
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class Messages method propagateFailure.
private void propagateFailure(BulkItemResponse[] items, List<Map.Entry<IndexSet, Message>> messageList, String errorMessage) {
final List<IndexFailure> indexFailures = new LinkedList<>();
for (BulkItemResponse item : items) {
if (item.isFailed()) {
LOG.trace("Failed to index message: {}", item.getFailureMessage());
// Write failure to index_failures.
final BulkItemResponse.Failure f = item.getFailure();
final Map.Entry<IndexSet, Message> messageEntry = messageList.get(item.getItemId());
final Map<String, Object> doc = ImmutableMap.<String, Object>builder().put("letter_id", item.getId()).put("index", f.getIndex()).put("type", f.getType()).put("message", f.getMessage()).put("timestamp", messageEntry.getValue().getTimestamp()).build();
indexFailures.add(new IndexFailureImpl(doc));
}
}
LOG.error("Failed to index [{}] messages. Please check the index error log in your web interface for the reason. Error: {}", indexFailures.size(), errorMessage);
try {
// TODO: Magic number
indexFailureQueue.offer(indexFailures, 25, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
LOG.warn("Couldn't save index failures.", e);
}
}
Aggregations