Search in sources :

Example 16 with NoAuditEvent

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

the class ClusterLoggersResource method setSubsystemLoggerLevel.

@PUT
@Timed
@Path("/{nodeId}/subsystems/{subsystem}/level/{level}")
@ApiOperation(value = "Set the loglevel of a whole subsystem", notes = "Provided level is falling back to DEBUG if it does not exist")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such subsystem.") })
@NoAuditEvent("proxy resource, audit event will be emitted on target nodes")
public void setSubsystemLoggerLevel(@ApiParam(name = "nodeId", required = true) @PathParam("nodeId") @NotEmpty String nodeId, @ApiParam(name = "subsystem", required = true) @PathParam("subsystem") @NotEmpty String subsystemTitle, @ApiParam(name = "level", required = true) @PathParam("level") @NotEmpty String level) throws NodeNotFoundException, IOException {
    final Node node = this.nodeService.byNodeId(nodeId);
    final RemoteLoggersResource remoteLoggersResource = this.remoteInterfaceProvider.get(node, this.authenticationToken, RemoteLoggersResource.class);
    remoteLoggersResource.setSubsystemLoggerLevel(subsystemTitle, level).execute();
}
Also used : Node(org.graylog2.cluster.Node) RemoteLoggersResource(org.graylog2.rest.resources.system.logs.RemoteLoggersResource) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 17 with NoAuditEvent

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

the class RuleResource method parse.

@ApiOperation(value = "Parse a processing rule without saving it", notes = "")
@POST
@Path("/parse")
@NoAuditEvent("only used to parse a rule, no changes made in the system")
public RuleSource parse(@ApiParam(name = "rule", required = true) @NotNull RuleSource ruleSource) throws ParseException {
    final Rule rule;
    try {
        // be silent about parse errors here, many requests will result in invalid syntax
        rule = pipelineRuleParser.parseRule(ruleSource.id(), ruleSource.source(), true);
    } catch (ParseException e) {
        throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(e.getErrors()).build());
    }
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    return RuleSource.builder().title(rule.name()).description(ruleSource.description()).source(ruleSource.source()).createdAt(now).modifiedAt(now).build();
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) ParseException(org.graylog.plugins.pipelineprocessor.parser.ParseException) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 18 with NoAuditEvent

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

the class SimulatorResource method simulate.

@ApiOperation(value = "Simulate the execution of the pipeline message processor")
@POST
@RequiresPermissions(PipelineRestPermissions.PIPELINE_RULE_READ)
@NoAuditEvent("only used to test pipelines, no changes made in the system")
public SimulationResponse simulate(@ApiParam(name = "simulation", required = true) @NotNull SimulationRequest request) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_READ, request.streamId());
    final Message message = new Message(request.message());
    // Save off the original message fields to compare post pipeline processing
    Map<String, Object> originalFields = new HashMap<>(message.getFields());
    final Stream stream = streamService.load(request.streamId());
    message.addStream(stream);
    if (!Strings.isNullOrEmpty(request.inputId())) {
        message.setSourceInputId(request.inputId());
    }
    final List<ResultMessageSummary> simulationResults = new ArrayList<>();
    final PipelineInterpreterTracer pipelineInterpreterTracer = new PipelineInterpreterTracer();
    org.graylog2.plugin.Messages processedMessages = pipelineInterpreter.process(message, pipelineInterpreterTracer.getSimulatorInterpreterListener(), pipelineStateUpdater.getLatestState());
    for (Message processedMessage : processedMessages) {
        ResultMessageSummary summary = ResultMessageSummary.create(null, processedMessage.getFields(), "");
        // generate the DecorationStats and add it to the summary
        DecorationStats decorationStats = DecorationStats.create(originalFields, processedMessage.getFields());
        simulationResults.add(summary.toBuilder().decorationStats(decorationStats).build());
    }
    return SimulationResponse.create(simulationResults, pipelineInterpreterTracer.getExecutionTrace(), pipelineInterpreterTracer.took());
}
Also used : Message(org.graylog2.plugin.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary) PipelineInterpreterTracer(org.graylog.plugins.pipelineprocessor.simulator.PipelineInterpreterTracer) Stream(org.graylog2.plugin.streams.Stream) DecorationStats(org.graylog2.rest.models.messages.responses.DecorationStats) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 19 with NoAuditEvent

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

the class SuggestionsResource method suggestFieldValue.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Suggest field value")
@NoAuditEvent("Only suggesting field value for query, not changing any data")
public SuggestionsDTO suggestFieldValue(@ApiParam(name = "validationRequest") SuggestionsRequestDTO suggestionsRequest, @Context SearchUser searchUser) {
    final SuggestionRequest req = SuggestionRequest.builder().field(suggestionsRequest.field()).input(suggestionsRequest.input()).streams(adaptStreams(suggestionsRequest.streams(), searchUser)).size(Math.min(suggestionsRequest.size(), SUGGESTIONS_COUNT_MAX)).timerange(Optional.ofNullable(suggestionsRequest.timerange()).orElse(defaultTimeRange())).build();
    SuggestionResponse res = querySuggestionsService.suggest(req);
    final List<SuggestionEntryDTO> suggestions = res.suggestions().stream().map(s -> SuggestionEntryDTO.create(s.getValue(), s.getOccurrence())).collect(Collectors.toList());
    final SuggestionsDTO.Builder suggestionsBuilder = SuggestionsDTO.builder(res.field(), res.input()).suggestions(suggestions).sumOtherDocsCount(res.sumOtherDocsCount());
    res.suggestionError().map(e -> SuggestionsErrorDTO.create(e.type(), e.reason())).ifPresent(suggestionsBuilder::error);
    return suggestionsBuilder.build();
}
Also used : InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Produces(javax.ws.rs.Produces) SuggestionEntryDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionEntryDTO) SuggestionsDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsDTO) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) SuggestionsErrorDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsErrorDTO) SuggestionsRequestDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsRequestDTO) PluginRestResource(org.graylog2.plugin.rest.PluginRestResource) Api(io.swagger.annotations.Api) SuggestionResponse(org.graylog.plugins.views.search.engine.suggestions.SuggestionResponse) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) ImmutableSet(com.google.common.collect.ImmutableSet) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) SuggestionRequest(org.graylog.plugins.views.search.engine.suggestions.SuggestionRequest) Collectors(java.util.stream.Collectors) List(java.util.List) QuerySuggestionsService(org.graylog.plugins.views.search.engine.QuerySuggestionsService) Optional(java.util.Optional) SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) SuggestionsDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionsDTO) SuggestionResponse(org.graylog.plugins.views.search.engine.suggestions.SuggestionResponse) SuggestionRequest(org.graylog.plugins.views.search.engine.suggestions.SuggestionRequest) SuggestionEntryDTO(org.graylog.plugins.views.search.rest.suggestions.SuggestionEntryDTO) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 20 with NoAuditEvent

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

the class MessagesResource method retrieveForSearch.

@ApiOperation(value = "Export a search result as CSV")
@POST
@Path("{searchId}")
@Produces(MoreMediaTypes.TEXT_CSV)
@NoAuditEvent("Has custom audit events")
public ChunkedOutput<SimpleMessageChunk> retrieveForSearch(@ApiParam(value = "ID of an existing Search", name = "searchId") @PathParam("searchId") String searchId, @ApiParam(value = "Optional overrides") @Valid ResultFormat formatFromClient, @Context SearchUser searchUser) {
    ResultFormat format = fillInIfNecessary(emptyIfNull(formatFromClient), searchUser);
    Search search = loadSearch(searchId, format.executionState(), searchUser);
    ExportMessagesCommand command = commandFactory.buildWithSearchOnly(search, format);
    return asyncRunner.apply(chunkConsumer -> exporter(searchId).export(command, chunkConsumer));
}
Also used : Search(org.graylog.plugins.views.search.Search) ResultFormat(org.graylog.plugins.views.search.export.ResultFormat) ExportMessagesCommand(org.graylog.plugins.views.search.export.ExportMessagesCommand) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) 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