Search in sources :

Example 86 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class ExtractorsResource method single.

@GET
@Timed
@ApiOperation(value = "Get information of a single extractor of an input")
@Path("/{extractorId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 404, message = "No such extractor on this input.") })
@Produces(MediaType.APPLICATION_JSON)
public ExtractorSummary single(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "extractorId", required = true) @PathParam("extractorId") final String extractorId) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_READ, inputId);
    final MessageInput input = persistedInputs.get(inputId);
    if (input == null) {
        LOG.error("Input <{}> not found.", inputId);
        throw new javax.ws.rs.NotFoundException("Couldn't find input " + inputId);
    }
    final Input mongoInput = inputService.find(input.getPersistId());
    final Extractor extractor = inputService.getExtractor(mongoInput, extractorId);
    return toSummary(extractor);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) Extractor(org.graylog2.plugin.inputs.Extractor) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 87 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class ExtractorsResource method terminate.

@DELETE
@Timed
@ApiOperation(value = "Delete an extractor")
@Path("/{extractorId}")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid request."), @ApiResponse(code = 404, message = "Input not found."), @ApiResponse(code = 404, message = "Extractor not found.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.EXTRACTOR_DELETE)
public void terminate(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "extractorId", required = true) @PathParam("extractorId") String extractorId) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    final MessageInput input = persistedInputs.get(inputId);
    if (input == null) {
        LOG.error("Input <{}> not found.", inputId);
        throw new javax.ws.rs.NotFoundException("Couldn't find input " + inputId);
    }
    // Remove from Mongo.
    final Input mongoInput = inputService.find(input.getPersistId());
    final Extractor extractor = inputService.getExtractor(mongoInput, extractorId);
    inputService.removeExtractor(mongoInput, extractor.getId());
    final String msg = "Deleted extractor <" + extractorId + "> of type [" + extractor.getType() + "] " + "from input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, InputsResource.class));
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) Activity(org.graylog2.shared.system.activities.Activity) Extractor(org.graylog2.plugin.inputs.Extractor) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 88 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class ExtractorsResource method order.

@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update extractor order of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@Path("order")
@AuditEvent(type = AuditEventTypes.EXTRACTOR_ORDER_UPDATE)
public void order(@ApiParam(name = "inputId", value = "Persist ID (!) of input.", required = true) @PathParam("inputId") String inputPersistId, @ApiParam(name = "JSON body", required = true) OrderExtractorsRequest oer) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputPersistId);
    final Input mongoInput = inputService.find(inputPersistId);
    for (Extractor extractor : inputService.getExtractors(mongoInput)) {
        if (oer.order().containsValue(extractor.getId())) {
            extractor.setOrder(Tools.getKeyByValue(oer.order(), extractor.getId()));
        }
        // Docs embedded in MongoDB array cannot be updated atomically... :/
        inputService.removeExtractor(mongoInput, extractor.getId());
        try {
            inputService.addExtractor(mongoInput, extractor);
        } catch (ValidationException e) {
            LOG.warn("Validation error for extractor update.", e);
        }
    }
    LOG.info("Updated extractor ordering of input <persist:{}>.", inputPersistId);
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) Extractor(org.graylog2.plugin.inputs.Extractor) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 89 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class ExtractorsResource method create.

@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add an extractor to an input", response = ExtractorCreated.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "No such extractor type."), @ApiResponse(code = 400, message = "Field the extractor should write on is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.EXTRACTOR_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    final Input mongoInput = inputService.find(inputId);
    final String id = new com.eaio.uuid.UUID().toString();
    final Extractor extractor = buildExtractorFromRequest(cer, id);
    try {
        inputService.addExtractor(mongoInput, extractor);
    } catch (ValidationException e) {
        final String msg = "Extractor persist validation failed.";
        LOG.error(msg, e);
        throw new BadRequestException(msg, e);
    }
    final String msg = "Added extractor <" + id + "> of type [" + cer.extractorType() + "] to input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, ExtractorsResource.class));
    final ExtractorCreated result = ExtractorCreated.create(id);
    final URI extractorUri = getUriBuilderToSelf().path(ExtractorsResource.class).path("{inputId}").build(mongoInput.getId());
    return Response.created(extractorUri).entity(result).build();
}
Also used : ExtractorCreated(org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorCreated) Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) BadRequestException(javax.ws.rs.BadRequestException) Activity(org.graylog2.shared.system.activities.Activity) Extractor(org.graylog2.plugin.inputs.Extractor) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 90 with Timed

use of com.codahale.metrics.annotation.Timed in project graylog2-server by Graylog2.

the class StreamRuleResource method update.

@PUT
@Path("/{streamRuleId}")
@Timed
@ApiOperation(value = "Update a stream rule")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream or stream rule not found."), @ApiResponse(code = 400, message = "Invalid JSON Body.") })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_RULE_UPDATE)
public SingleStreamRuleSummaryResponse update(@ApiParam(name = "streamid", value = "The stream id this rule belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "streamRuleId", value = "The stream rule id we are updating", required = true) @PathParam("streamRuleId") String streamRuleId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStreamRuleRequest cr) throws NotFoundException, ValidationException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    checkNotDefaultStream(streamid, "Cannot update stream rules on default stream.");
    final StreamRule streamRule;
    streamRule = streamRuleService.load(streamRuleId);
    if (!streamRule.getStreamId().equals(streamid)) {
        throw new NotFoundException("Couldn't update stream rule " + streamRuleId + "in stream " + streamid);
    }
    final StreamRuleType streamRuleType = StreamRuleType.fromInteger(cr.type());
    if (null == streamRuleType) {
        throw new BadRequestException("Unknown stream rule type " + cr.type());
    }
    streamRule.setField(cr.field());
    streamRule.setType(streamRuleType);
    streamRule.setInverted(cr.inverted());
    streamRule.setValue(cr.value());
    streamRule.setDescription(cr.description());
    streamRuleService.save(streamRule);
    clusterEventBus.post(StreamsChangedEvent.create(streamid));
    return SingleStreamRuleSummaryResponse.create(streamRule.getId());
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) StreamRuleType(org.graylog2.plugin.streams.StreamRuleType) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)414 ApiOperation (io.swagger.annotations.ApiOperation)255 ApiResponses (io.swagger.annotations.ApiResponses)196 Path (javax.ws.rs.Path)169 Counted (com.codahale.metrics.annotation.Counted)128 Produces (javax.ws.rs.Produces)112 GET (javax.ws.rs.GET)107 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)105 AuditEvent (org.graylog2.audit.jersey.AuditEvent)82 POST (javax.ws.rs.POST)78 Consumes (javax.ws.rs.Consumes)58 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)53 NotFoundException (javax.ws.rs.NotFoundException)52 PUT (javax.ws.rs.PUT)52 URI (java.net.URI)45 DELETE (javax.ws.rs.DELETE)45 BadRequestException (javax.ws.rs.BadRequestException)41 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)41 HashMap (java.util.HashMap)34 Event (keywhiz.log.Event)29