use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class StaticFieldsResource method create.
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add a static field to an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "Field/Key is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStaticFieldRequest csfr) throws NotFoundException, ValidationException {
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
final MessageInput input = persistedInputs.get(inputId);
if (input == null) {
final String msg = "Input <" + inputId + "> not found.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
// Check if key is a valid message key.
if (!Message.validKey(csfr.key())) {
final String msg = "Invalid key: [" + csfr.key() + "]";
LOG.error(msg);
throw new BadRequestException(msg);
}
if (Message.RESERVED_FIELDS.contains(csfr.key()) && !Message.RESERVED_SETTABLE_FIELDS.contains(csfr.key())) {
final String message = "Cannot add static field. Field [" + csfr.key() + "] is reserved.";
LOG.error(message);
throw new BadRequestException(message);
}
input.addStaticField(csfr.key(), csfr.value());
final Input mongoInput = inputService.find(input.getPersistId());
inputService.addStaticField(mongoInput, csfr.key(), csfr.value());
final String msg = "Added static field [" + csfr.key() + "] to input <" + inputId + ">.";
LOG.info(msg);
activityWriter.write(new Activity(msg, StaticFieldsResource.class));
final URI inputUri = getUriBuilderToSelf().path(InputsResource.class).path("{inputId}").build(mongoInput.getId());
return Response.created(inputUri).build();
}
use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class StaticFieldsResource method delete.
@DELETE
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Remove static field of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 404, message = "No such static field.") })
@Path("/{key}")
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_DELETE)
public void delete(@ApiParam(name = "Key", required = true) @PathParam("key") String key, @ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws NotFoundException {
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
MessageInput input = persistedInputs.get(inputId);
if (input == null) {
final String msg = "Input <" + inputId + "> not found.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
if (!input.getStaticFields().containsKey(key)) {
final String msg = "No such static field [" + key + "] on input <" + inputId + ">.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
input.getStaticFields().remove(key);
Input mongoInput = inputService.find(input.getPersistId());
inputService.removeStaticField(mongoInput, key);
final String msg = "Removed static field [" + key + "] of input <" + inputId + ">.";
LOG.info(msg);
activityWriter.write(new Activity(msg, StaticFieldsResource.class));
}
use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class DeflectorResource method deprecatedCycle.
@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
@Deprecated
public void deprecatedCycle() {
final IndexSet indexSet = indexSetRegistry.getDefault();
checkCycle(indexSet);
final String msg = "Cycling deflector for default index set <" + indexSet.getConfig().id() + ">. Reason: REST request.";
LOG.info(msg);
activityWriter.write(new Activity(msg, DeflectorResource.class));
indexSet.cycle();
}
Aggregations