use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class ConfigurationResource method copyConfiguration.
@POST
@Path("/{id}/{name}")
@RequiresPermissions({ SidecarRestPermissions.CONFIGURATIONS_READ, SidecarRestPermissions.CONFIGURATIONS_CREATE })
@ApiOperation(value = "Copy a configuration")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_CLONE)
public Response copyConfiguration(@ApiParam(name = "id", required = true) @PathParam("id") String id, @PathParam("name") String name) throws NotFoundException {
final Configuration configuration = configurationService.copyConfiguration(id, name);
final ValidationResult validationResult = validate(configuration);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
configurationService.save(configuration);
return Response.accepted().build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class SidecarResource method assignConfiguration.
@PUT
@Timed
@Path("/configurations")
@ApiOperation(value = "Assign configurations to sidecars")
@RequiresPermissions(SidecarRestPermissions.SIDECARS_UPDATE)
@AuditEvent(type = SidecarAuditEventTypes.SIDECAR_UPDATE)
public Response assignConfiguration(@ApiParam(name = "JSON body", required = true) @Valid @NotNull NodeConfigurationRequest request) throws NotFoundException {
List<String> nodeIdList = request.nodes().stream().filter(distinctByKey(NodeConfiguration::nodeId)).map(NodeConfiguration::nodeId).collect(Collectors.toList());
for (String nodeId : nodeIdList) {
List<ConfigurationAssignment> nodeRelations = request.nodes().stream().filter(a -> a.nodeId().equals(nodeId)).flatMap(a -> a.assignments().stream()).collect(Collectors.toList());
try {
Sidecar sidecar = sidecarService.assignConfiguration(nodeId, nodeRelations);
sidecarService.save(sidecar);
} catch (org.graylog2.database.NotFoundException e) {
throw new NotFoundException(e.getMessage());
}
}
return Response.accepted().build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class CollectorResource method copyCollector.
@POST
@Path("/{id}/{name}")
@RequiresPermissions({ SidecarRestPermissions.COLLECTORS_READ, SidecarRestPermissions.COLLECTORS_CREATE })
@ApiOperation(value = "Copy a collector")
@AuditEvent(type = SidecarAuditEventTypes.COLLECTOR_CLONE)
public Response copyCollector(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "name", required = true) @PathParam("name") String name) throws NotFoundException, BadRequestException {
final Collector collector = collectorService.copy(id, name);
final ValidationResult validationResult = validate(collector);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
etagService.invalidateAll();
collectorService.save(collector);
return Response.accepted().build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class CollectorResource method createCollector.
@POST
@RequiresPermissions(SidecarRestPermissions.COLLECTORS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a new collector")
@AuditEvent(type = SidecarAuditEventTypes.COLLECTOR_CREATE)
public Response createCollector(@ApiParam(name = "JSON body", required = true) @Valid @NotNull Collector request) throws BadRequestException {
Collector collector = collectorService.fromRequest(request);
final ValidationResult validationResult = validate(collector);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
etagService.invalidateAll();
return Response.ok().entity(collectorService.save(collector)).build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class EventDefinitionsResource method update.
@PUT
@Path("{definitionId}")
@ApiOperation("Update existing event definition")
@AuditEvent(type = EventsAuditEventTypes.EVENT_DEFINITION_UPDATE)
public Response update(@ApiParam(name = "definitionId") @PathParam("definitionId") @NotBlank String definitionId, @ApiParam("schedule") @QueryParam("schedule") @DefaultValue("true") boolean schedule, @ApiParam(name = "JSON Body") EventDefinitionDto dto) {
checkPermission(RestPermissions.EVENT_DEFINITIONS_EDIT, definitionId);
checkEventDefinitionPermissions(dto, "update");
dbService.get(definitionId).orElseThrow(() -> new NotFoundException("Event definition <" + definitionId + "> doesn't exist"));
final ValidationResult result = dto.validate();
if (!definitionId.equals(dto.id())) {
result.addError("id", "Event definition IDs don't match");
}
if (result.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(result).build();
}
return Response.ok().entity(eventDefinitionHandler.update(dto, schedule)).build();
}
Aggregations