Search in sources :

Example 11 with NoAuditEvent

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

the class QueryValidationResource method validateQuery.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Validate a search query")
@NoAuditEvent("Only validating query structure, not changing any data")
public ValidationResponseDTO validateQuery(@ApiParam(name = "validationRequest") ValidationRequestDTO validationRequest, @Context SearchUser searchUser) {
    final ValidationRequest.Builder q = ValidationRequest.Builder.builder().query(validationRequest.query()).timerange(validationRequest.timerange().orElse(defaultTimeRange())).streams(searchUser.streams().readableOrAllIfEmpty(validationRequest.streams())).parameters(resolveParameters(validationRequest));
    validationRequest.filter().ifPresent(q::filter);
    final ValidationResponse response = queryValidationService.validate(q.build());
    return ValidationResponseDTO.create(toStatus(response.status()), toExplanations(response));
}
Also used : ValidationResponse(org.graylog.plugins.views.search.validation.ValidationResponse) ValidationRequest(org.graylog.plugins.views.search.validation.ValidationRequest) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 12 with NoAuditEvent

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

the class SearchResource method executeSyncJobv2.

@POST
@ApiOperation(value = "Execute a new synchronous search", notes = "Executes a new search and waits for its result", response = SearchJobDTO.class)
@Path("sync")
@NoAuditEvent("Creating audit event manually in method body.")
@Consumes({ SEARCH_FORMAT_V2 })
@Produces({ SEARCH_FORMAT_V2 })
public Response executeSyncJobv2(@ApiParam @NotNull(message = "Search body is mandatory") SearchDTOv2 searchRequest, @ApiParam(name = "timeout", defaultValue = "60000") @QueryParam("timeout") @DefaultValue("60000") long timeout, @Context SearchUser searchUser) {
    final Search search = searchRequest.toSearch();
    final SearchJob searchJob = searchExecutor.execute(search, searchUser, ExecutionState.empty());
    postAuditEvent(searchJob);
    final SearchJobDTO searchJobDTO = SearchJobDTO.fromSearchJob(searchJob);
    return Response.ok(searchJobDTO).build();
}
Also used : Search(org.graylog.plugins.views.search.Search) SearchJob(org.graylog.plugins.views.search.SearchJob) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 13 with NoAuditEvent

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

the class SearchResource method executeSyncJob.

@POST
@ApiOperation(value = "Execute a new synchronous search", notes = "Executes a new search and waits for its result", response = SearchJobDTO.class)
@Path("sync")
@NoAuditEvent("Creating audit event manually in method body.")
@Consumes({ MediaType.APPLICATION_JSON, SEARCH_FORMAT_V1 })
@Produces({ MediaType.APPLICATION_JSON, SEARCH_FORMAT_V1 })
public Response executeSyncJob(@ApiParam @NotNull(message = "Search body is mandatory") SearchDTO searchRequest, @ApiParam(name = "timeout", defaultValue = "60000") @QueryParam("timeout") @DefaultValue("60000") long timeout, @Context SearchUser searchUser) {
    final Search search = searchRequest.toSearch();
    final SearchJob searchJob = searchExecutor.execute(search, searchUser, ExecutionState.empty());
    postAuditEvent(searchJob);
    final SearchJobDTO searchJobDTO = SearchJobDTO.fromSearchJob(searchJob);
    return Response.ok(searchJobDTO).build();
}
Also used : Search(org.graylog.plugins.views.search.Search) SearchJob(org.graylog.plugins.views.search.SearchJob) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 14 with NoAuditEvent

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

the class SearchMetadataResource method metadataForObject.

@POST
@ApiOperation(value = "Metadata for the posted Search object", notes = "Intended for search objects that aren't yet persisted (e.g. for validation or interactive purposes)")
@NoAuditEvent("Only returning metadata for given search, not changing any data")
public SearchMetadata metadataForObject(@ApiParam @NotNull(message = "Search body is mandatory") SearchDTO searchDTO) {
    if (searchDTO == null) {
        throw new IllegalArgumentException("Search must not be null.");
    }
    final Search search = searchDTO.toSearch();
    final Map<String, QueryMetadata> queryMetadatas = StreamEx.of(search.queries()).toMap(Query::id, query -> queryEngine.parse(search, query));
    return SearchMetadata.create(queryMetadatas, Maps.uniqueIndex(search.parameters(), Parameter::name));
}
Also used : QueryMetadata(org.graylog.plugins.views.search.QueryMetadata) Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 15 with NoAuditEvent

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

the class StreamAlertResource method sendDummyAlert.

@POST
@Timed
@Path("sendDummyAlert")
@ApiOperation(value = "Send a test mail for a given stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 400, message = "Stream has no alarm callbacks") })
@NoAuditEvent("only used to test alert emails")
public void sendDummyAlert(@ApiParam(name = "streamId", value = "The stream id the test alert should be sent for.", required = true) @PathParam("streamId") String streamId) throws TransportConfigurationException, EmailException, NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamId);
    final Stream stream = streamService.load(streamId);
    final DummyAlertCondition dummyAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
    try {
        AbstractAlertCondition.CheckResult checkResult = dummyAlertCondition.runCheck();
        List<AlarmCallbackConfiguration> callConfigurations = alarmCallbackConfigurationService.getForStream(stream);
        if (callConfigurations.size() == 0) {
            final String message = "Stream has no alarm callbacks, cannot send test alert.";
            LOG.warn(message);
            throw new BadRequestException(message);
        }
        for (AlarmCallbackConfiguration configuration : callConfigurations) {
            AlarmCallback alarmCallback = alarmCallbackFactory.create(configuration);
            alarmCallback.call(stream, checkResult);
        }
    } catch (AlarmCallbackException | ClassNotFoundException | AlarmCallbackConfigurationException e) {
        throw new InternalServerErrorException(e.getMessage(), e);
    }
}
Also used : AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) 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