Search in sources :

Example 11 with AuditEvent

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();
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 12 with AuditEvent

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();
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) CollectorActions(org.graylog.plugins.sidecar.rest.models.CollectorActions) Produces(javax.ws.rs.Produces) SidecarService(org.graylog.plugins.sidecar.services.SidecarService) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) NodeConfiguration(org.graylog.plugins.sidecar.rest.models.NodeConfiguration) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) PaginatedList(org.graylog2.database.PaginatedList) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) SidecarConfiguration(org.graylog.plugins.sidecar.system.SidecarConfiguration) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) SearchQueryField(org.graylog2.search.SearchQueryField) Map(java.util.Map) PluginRestResource(org.graylog2.plugin.rest.PluginRestResource) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) BadRequestException(javax.ws.rs.BadRequestException) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) CollectorAction(org.graylog.plugins.sidecar.rest.models.CollectorAction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) RegistrationRequest(org.graylog.plugins.sidecar.rest.requests.RegistrationRequest) List(java.util.List) SidecarSummary(org.graylog.plugins.sidecar.rest.models.SidecarSummary) Response(javax.ws.rs.core.Response) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) ConfigurationAssignment(org.graylog.plugins.sidecar.rest.requests.ConfigurationAssignment) PathParam(javax.ws.rs.PathParam) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar) SearchQueryParser(org.graylog2.search.SearchQueryParser) GET(javax.ws.rs.GET) SidecarRegistrationConfiguration(org.graylog.plugins.sidecar.rest.models.SidecarRegistrationConfiguration) NodeConfigurationRequest(org.graylog.plugins.sidecar.rest.requests.NodeConfigurationRequest) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) RegistrationResponse(org.graylog.plugins.sidecar.rest.responses.RegistrationResponse) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Api(io.swagger.annotations.Api) SidecarRestPermissions(org.graylog.plugins.sidecar.permissions.SidecarRestPermissions) SearchQuery(org.graylog2.search.SearchQuery) ActiveSidecarFilter(org.graylog.plugins.sidecar.filter.ActiveSidecarFilter) DateTime(org.joda.time.DateTime) SidecarAuditEventTypes(org.graylog.plugins.sidecar.audit.SidecarAuditEventTypes) RestResource(org.graylog2.shared.rest.resources.RestResource) SidecarListResponse(org.graylog.plugins.sidecar.rest.responses.SidecarListResponse) ActionService(org.graylog.plugins.sidecar.services.ActionService) ApiResponse(io.swagger.annotations.ApiResponse) NotEmpty(org.hibernate.validator.constraints.NotEmpty) PUT(javax.ws.rs.PUT) SidecarStatusMapper(org.graylog.plugins.sidecar.mapper.SidecarStatusMapper) ConfigurationAssignment(org.graylog.plugins.sidecar.rest.requests.ConfigurationAssignment) NotFoundException(javax.ws.rs.NotFoundException) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 13 with AuditEvent

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();
}
Also used : Collector(org.graylog.plugins.sidecar.rest.models.Collector) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 14 with AuditEvent

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();
}
Also used : Collector(org.graylog.plugins.sidecar.rest.models.Collector) ValidationResult(org.graylog2.plugin.rest.ValidationResult) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 15 with AuditEvent

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();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Aggregations

AuditEvent (org.graylog2.audit.jersey.AuditEvent)134 ApiOperation (io.swagger.annotations.ApiOperation)132 Path (javax.ws.rs.Path)100 Timed (com.codahale.metrics.annotation.Timed)87 ApiResponses (io.swagger.annotations.ApiResponses)64 PUT (javax.ws.rs.PUT)55 POST (javax.ws.rs.POST)52 Produces (javax.ws.rs.Produces)48 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)47 BadRequestException (javax.ws.rs.BadRequestException)46 Consumes (javax.ws.rs.Consumes)38 DELETE (javax.ws.rs.DELETE)34 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)33 NotFoundException (javax.ws.rs.NotFoundException)24 URI (java.net.URI)22 ValidationException (org.graylog2.plugin.database.ValidationException)16 Stream (org.graylog2.plugin.streams.Stream)16 NotFoundException (org.graylog2.database.NotFoundException)15 User (org.graylog2.plugin.database.users.User)14 ValidationResult (org.graylog2.plugin.rest.ValidationResult)12