use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RawMessage method getRemoteAddress.
@Nullable
public ResolvableInetSocketAddress getRemoteAddress() {
if (msgBuilder.hasRemote()) {
final JournalMessages.RemoteAddress address = msgBuilder.getRemote();
final InetAddress inetAddr;
try {
inetAddr = InetAddress.getByAddress(address.getResolved(), address.getAddress().toByteArray());
} catch (UnknownHostException e) {
log.warn("Malformed InetAddress for message {}, expected 4 or 16 bytes, but got {} bytes", id, address.getAddress().toByteArray());
return null;
}
final int port = address.hasPort() ? address.getPort() : 0;
// TODO PERFORMANCE object creation
return ResolvableInetSocketAddress.wrap(new InetSocketAddress(inetAddr, port));
}
return null;
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class RawMessage method encode.
public byte[] encode() {
try {
final JournalMessages.CodecInfo codec = msgBuilder.getCodec();
final JournalMessages.CodecInfo.Builder builder = JournalMessages.CodecInfo.newBuilder(codec);
final String codecConfigJson = codecConfig.serializeToJson();
if (codecConfigJson != null) {
builder.setConfig(codecConfigJson);
}
msgBuilder.setCodec(builder.build());
final JournalMessage journalMessage = msgBuilder.build();
return journalMessage.toByteArray();
} catch (UninitializedMessageException e) {
log.error("Unable to write RawMessage to journal because required fields are missing, " + "this message will be discarded. This is a bug.", e);
return null;
}
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class ExtractorsResource method order.
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update extractor order of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@Path("order")
@AuditEvent(type = AuditEventTypes.EXTRACTOR_ORDER_UPDATE)
public void order(@ApiParam(name = "inputId", value = "Persist ID (!) of input.", required = true) @PathParam("inputId") String inputPersistId, @ApiParam(name = "JSON body", required = true) OrderExtractorsRequest oer) throws NotFoundException {
checkPermission(RestPermissions.INPUTS_EDIT, inputPersistId);
final Input mongoInput = inputService.find(inputPersistId);
for (Extractor extractor : inputService.getExtractors(mongoInput)) {
if (oer.order().containsValue(extractor.getId())) {
extractor.setOrder(Tools.getKeyByValue(oer.order(), extractor.getId()));
}
// Docs embedded in MongoDB array cannot be updated atomically... :/
inputService.removeExtractor(mongoInput, extractor.getId());
try {
inputService.addExtractor(mongoInput, extractor);
} catch (ValidationException e) {
LOG.warn("Validation error for extractor update.", e);
}
}
LOG.info("Updated extractor ordering of input <persist:{}>.", inputPersistId);
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class InputsResource method get.
@GET
@Timed
@ApiOperation(value = "Get information of a single input on this node")
@Path("/{inputId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input.") })
public InputSummary get(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
checkPermission(RestPermissions.INPUTS_READ, inputId);
final Input input = inputService.find(inputId);
return getInputSummary(input);
}
use of org.graylog2.plugin.Message in project graylog2-server by Graylog2.
the class InputsResource method terminate.
@DELETE
@Timed
@Path("/{inputId}")
@ApiOperation(value = "Terminate input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_DELETE)
public void terminate(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
checkPermission(RestPermissions.INPUTS_TERMINATE, inputId);
final Input input = inputService.find(inputId);
inputService.destroy(input);
}
Aggregations