Search in sources :

Example 61 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class InputsResource method create.

@POST
@Timed
@ApiOperation(value = "Launch input on this node", response = InputCreated.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input type registered"), @ApiResponse(code = 400, message = "Missing or invalid configuration"), @ApiResponse(code = 400, message = "Type is exclusive and already has input running") })
@RequiresPermissions(RestPermissions.INPUTS_CREATE)
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) @Valid @NotNull InputCreateRequest lr) throws ValidationException {
    try {
        // TODO Configuration type values need to be checked. See ConfigurationMapConverter.convertValues()
        final MessageInput messageInput = messageInputFactory.create(lr, getCurrentUser().getName(), lr.node());
        messageInput.checkConfiguration();
        final Input input = this.inputService.create(messageInput.asMap());
        final String newId = inputService.save(input);
        final URI inputUri = getUriBuilderToSelf().path(InputsResource.class).path("{inputId}").build(newId);
        return Response.created(inputUri).entity(InputCreated.create(newId)).build();
    } catch (NoSuchInputTypeException e) {
        LOG.error("There is no such input type registered.", e);
        throw new NotFoundException("There is no such input type registered.", e);
    } catch (ConfigurationException e) {
        LOG.error("Missing or invalid input configuration.", e);
        throw new BadRequestException("Missing or invalid input configuration.", e);
    }
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) MessageInput(org.graylog2.plugin.inputs.MessageInput) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 62 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class StaticFieldsResource method create.

@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add a static field to an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "Field/Key is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStaticFieldRequest csfr) throws NotFoundException, ValidationException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    final MessageInput input = persistedInputs.get(inputId);
    if (input == null) {
        final String msg = "Input <" + inputId + "> not found.";
        LOG.error(msg);
        throw new javax.ws.rs.NotFoundException(msg);
    }
    // Check if key is a valid message key.
    if (!Message.validKey(csfr.key())) {
        final String msg = "Invalid key: [" + csfr.key() + "]";
        LOG.error(msg);
        throw new BadRequestException(msg);
    }
    if (Message.RESERVED_FIELDS.contains(csfr.key()) && !Message.RESERVED_SETTABLE_FIELDS.contains(csfr.key())) {
        final String message = "Cannot add static field. Field [" + csfr.key() + "] is reserved.";
        LOG.error(message);
        throw new BadRequestException(message);
    }
    input.addStaticField(csfr.key(), csfr.value());
    final Input mongoInput = inputService.find(input.getPersistId());
    inputService.addStaticField(mongoInput, csfr.key(), csfr.value());
    final String msg = "Added static field [" + csfr.key() + "] to input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, StaticFieldsResource.class));
    final URI inputUri = getUriBuilderToSelf().path(InputsResource.class).path("{inputId}").build(mongoInput.getId());
    return Response.created(inputUri).build();
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) Activity(org.graylog2.shared.system.activities.Activity) 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 63 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class StaticFieldsResource method delete.

@DELETE
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Remove static field of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 404, message = "No such static field.") })
@Path("/{key}")
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_DELETE)
public void delete(@ApiParam(name = "Key", required = true) @PathParam("key") String key, @ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT, inputId);
    MessageInput input = persistedInputs.get(inputId);
    if (input == null) {
        final String msg = "Input <" + inputId + "> not found.";
        LOG.error(msg);
        throw new javax.ws.rs.NotFoundException(msg);
    }
    if (!input.getStaticFields().containsKey(key)) {
        final String msg = "No such static field [" + key + "] on input <" + inputId + ">.";
        LOG.error(msg);
        throw new javax.ws.rs.NotFoundException(msg);
    }
    input.getStaticFields().remove(key);
    Input mongoInput = inputService.find(input.getPersistId());
    inputService.removeStaticField(mongoInput, key);
    final String msg = "Removed static field [" + key + "] of input <" + inputId + ">.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, StaticFieldsResource.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) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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 64 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class StreamOutputResource method remove.

@DELETE
@Path("/{outputId}")
@Timed
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete output of a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_DELETE)
public void remove(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    checkPermission(RestPermissions.STREAM_OUTPUTS_DELETE, outputId);
    final Stream stream = streamService.load(streamid);
    final Output output = outputService.load(outputId);
    streamService.removeOutput(stream, output);
    outputRegistry.removeOutput(output);
}
Also used : Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) 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 65 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class InputStatesResource method stop.

@DELETE
@Path("/{inputId}")
@Timed
@ApiOperation(value = "Stop specified input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_STOP)
public InputDeleted stop(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    checkPermission(RestPermissions.INPUTS_CHANGESTATE, inputId);
    final Input input = inputService.find(inputId);
    persistDesiredState(input, IOState.Type.STOPPED);
    final InputDeleted result = InputDeleted.create(inputId);
    this.serverEventBus.post(result);
    return result;
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) InputDeleted(org.graylog2.rest.models.system.inputs.responses.InputDeleted) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)29 ApiOperation (io.swagger.annotations.ApiOperation)28 MessageInput (org.graylog2.plugin.inputs.MessageInput)23 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)19 Input (org.graylog2.inputs.Input)15 AuditEvent (org.graylog2.audit.jersey.AuditEvent)14 Test (org.junit.Test)14 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 Node (org.graylog2.cluster.Node)12 Map (java.util.Map)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 PUT (javax.ws.rs.PUT)6 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)6 Notification (org.graylog2.notifications.Notification)6 Activity (org.graylog2.shared.system.activities.Activity)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 EventBus (com.google.common.eventbus.EventBus)5 URI (java.net.URI)5