Search in sources :

Example 6 with NoSuchInputTypeException

use of org.graylog2.shared.inputs.NoSuchInputTypeException in project graylog2-server by Graylog2.

the class InputServiceImpl method getMessageInput.

@Override
public MessageInput getMessageInput(Input io) throws NoSuchInputTypeException {
    final Configuration configuration = new Configuration(io.getConfiguration());
    final MessageInput input = messageInputFactory.create(io.getType(), configuration);
    // Add all standard fields.
    input.setTitle(io.getTitle());
    input.setNodeId(io.getNodeId());
    input.setCreatorUserId(io.getCreatorUserId());
    input.setPersistId(io.getId());
    input.setCreatedAt(io.getCreatedAt());
    input.setContentPack(io.getContentPack());
    input.setDesiredState(io.getDesiredState());
    if (io.isGlobal()) {
        input.setGlobal(true);
    }
    // Add static fields.
    input.addStaticFields(io.getStaticFields());
    return input;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 7 with NoSuchInputTypeException

use of org.graylog2.shared.inputs.NoSuchInputTypeException 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 8 with NoSuchInputTypeException

use of org.graylog2.shared.inputs.NoSuchInputTypeException in project graylog2-server by Graylog2.

the class MessageInputFactory method create.

public MessageInput create(InputCreateRequest lr, String user, String nodeId) throws NoSuchInputTypeException {
    final MessageInput input = create(lr.type(), new Configuration(lr.configuration()));
    input.setTitle(lr.title());
    input.setGlobal(lr.global());
    input.setCreatorUserId(user);
    input.setCreatedAt(Tools.nowUTC());
    if (!lr.global())
        input.setNodeId(nodeId);
    return input;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Aggregations

MessageInput (org.graylog2.plugin.inputs.MessageInput)8 Configuration (org.graylog2.plugin.configuration.Configuration)4 Input (org.graylog2.inputs.Input)3 Timed (com.codahale.metrics.annotation.Timed)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2 NoSuchInputTypeException (org.graylog2.shared.inputs.NoSuchInputTypeException)2 DateTime (org.joda.time.DateTime)2 BadRequestException (javax.ws.rs.BadRequestException)1 NotFoundException (javax.ws.rs.NotFoundException)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 ConfigurationException (org.graylog2.plugin.configuration.ConfigurationException)1