Search in sources :

Example 31 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class LookupTableResource method validateAdapter.

@POST
@Path("adapters/validate")
@NoAuditEvent("Validation only")
@ApiOperation(value = "Validate the data adapter config")
@RequiresPermissions(RestPermissions.LOOKUP_TABLES_READ)
public ValidationResult validateAdapter(@Valid @ApiParam DataAdapterApi toValidate) {
    final ValidationResult validation = new ValidationResult();
    final Optional<DataAdapterDto> dtoOptional = dbDataAdapterService.get(toValidate.name());
    if (dtoOptional.isPresent()) {
        // an adapter exist with the given name, check that the IDs are the same, this might be an update
        final DataAdapterDto adapterDto = dtoOptional.get();
        // noinspection ConstantConditions
        if (!adapterDto.id().equals(toValidate.id())) {
            // an adapter exists with a different id, so the name is already in use, fail validation
            validation.addError("name", "The data adapter name is already in use.");
        }
    }
    final Optional<Multimap<String, String>> configValidations = toValidate.config().validate(lookupDataAdapterValidationContext);
    configValidations.ifPresent(validation::addAll);
    return validation;
}
Also used : Multimap(com.google.common.collect.Multimap) DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) 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)

Example 32 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class MetricsResource method multipleMetrics.

@POST
@Timed
@Path("/multiple")
@ApiOperation("Get the values of multiple metrics at once")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Malformed body") })
@NoAuditEvent("only used to retrieve multiple metrics")
public MetricsSummaryResponse multipleMetrics(@ApiParam(name = "Requested metrics", required = true) @Valid @NotNull MetricsReadRequest request) {
    final Map<String, Metric> metrics = metricRegistry.getMetrics();
    final List<Map<String, Object>> metricsList = Lists.newArrayList();
    for (String name : request.metrics()) {
        if (!isPermitted(RestPermissions.METRICS_READ, name)) {
            continue;
        }
        final Metric metric = metrics.get(name);
        if (metric != null) {
            metricsList.add(MetricUtils.map(name, metric));
        }
    }
    return MetricsSummaryResponse.create(metricsList);
}
Also used : Metric(com.codahale.metrics.Metric) Map(java.util.Map) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 33 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class EventNotificationsResource method test.

@POST
@Timed
@Path("/test")
@RequiresPermissions(RestPermissions.EVENT_NOTIFICATIONS_CREATE)
@ApiOperation(value = "Send a test alert for a given event notification")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Event notification is invalid."), @ApiResponse(code = 500, message = "Error while testing event notification") })
@NoAuditEvent("only used to test event notifications")
public Response test(@ApiParam(name = "JSON Body") NotificationDto dto) {
    checkPermission(RestPermissions.EVENT_NOTIFICATIONS_CREATE);
    final ValidationResult validationResult = dto.validate();
    if (validationResult.failed()) {
        return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
    }
    resourceHandler.test(dto, getSubject().getPrincipal().toString());
    return Response.ok().build();
}
Also used : ValidationResult(org.graylog2.plugin.rest.ValidationResult) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 34 with NoAuditEvent

use of org.graylog2.audit.jersey.NoAuditEvent in project graylog2-server by Graylog2.

the class EventNotificationsResource method test.

@POST
@Timed
@Path("/{notificationId}/test")
@ApiOperation(value = "Send a test alert for a given event notification")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Event notification not found."), @ApiResponse(code = 500, message = "Error while testing event notification") })
@NoAuditEvent("only used to test event notifications")
public Response test(@ApiParam(name = "notificationId", value = "The event notification id to send a test alert for.", required = true) @PathParam("notificationId") @NotBlank String notificationId) {
    checkPermission(RestPermissions.EVENT_NOTIFICATIONS_EDIT, notificationId);
    final NotificationDto notificationDto = dbNotificationService.get(notificationId).orElseThrow(() -> new NotFoundException("Notification " + notificationId + " doesn't exist"));
    resourceHandler.test(notificationDto, getSubject().getPrincipal().toString());
    return Response.ok().build();
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)33 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)33 POST (javax.ws.rs.POST)30 Path (javax.ws.rs.Path)27 Timed (com.codahale.metrics.annotation.Timed)14 ApiResponses (io.swagger.annotations.ApiResponses)10 Produces (javax.ws.rs.Produces)10 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)10 BadRequestException (javax.ws.rs.BadRequestException)9 Consumes (javax.ws.rs.Consumes)6 Stream (org.graylog2.plugin.streams.Stream)6 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)5 PUT (javax.ws.rs.PUT)5 Search (org.graylog.plugins.views.search.Search)5 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)4 ValidationResult (org.graylog2.plugin.rest.ValidationResult)4 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3