Search in sources :

Example 61 with MessageInput

use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.

the class NettyTransport method getChannelHandlers.

/**
 * Subclasses can override this to add additional {@link ChannelHandler channel handlers} to the
 * Netty {@link ChannelPipeline} to support additional features.
 *
 * Some common use cases are to add connection counters or traffic shapers.
 *
 * @param input The {@link MessageInput} for which these channel handlers are being added
 * @return list of initial {@link ChannelHandler channel handlers} to add to the Netty {@link ChannelPipeline channel pipeline}
 */
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChannelHandlers(final MessageInput input) {
    LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = new LinkedHashMap<>();
    handlerList.put("exception-logger", () -> new ExceptionLoggingChannelHandler(input, log));
    handlerList.put("packet-meta-dumper", () -> new PacketInformationDumper(input));
    handlerList.put("output-failure-logger", () -> PromiseFailureHandler.INSTANCE);
    return handlerList;
}
Also used : ExceptionLoggingChannelHandler(org.graylog2.inputs.transports.netty.ExceptionLoggingChannelHandler) ChannelHandler(io.netty.channel.ChannelHandler) ExceptionLoggingChannelHandler(org.graylog2.inputs.transports.netty.ExceptionLoggingChannelHandler) PacketInformationDumper(org.graylog2.plugin.inputs.util.PacketInformationDumper) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap)

Example 62 with MessageInput

use of org.graylog2.plugin.inputs.MessageInput 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 63 with MessageInput

use of org.graylog2.plugin.inputs.MessageInput 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 64 with MessageInput

use of org.graylog2.plugin.inputs.MessageInput 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 65 with MessageInput

use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.

the class GenericBindings method configure.

@Override
protected void configure() {
    // must not be a singleton!
    bind(LocalMetricRegistry.class).in(Scopes.NO_SCOPE);
    install(new FactoryModuleBuilder().build(DecodingProcessor.Factory.class));
    bind(ProcessBuffer.class).asEagerSingleton();
    if (isMigrationCommand) {
        bind(InputBuffer.class).to(NoopInputBuffer.class);
    } else {
        bind(InputBuffer.class).to(InputBufferImpl.class);
    }
    bind(NodeId.class).toProvider(NodeIdProvider.class);
    if (!isMigrationCommand) {
        bind(ServiceManager.class).toProvider(ServiceManagerProvider.class).asEagerSingleton();
    }
    bind(ThroughputCounter.class);
    bind(EventBus.class).toProvider(EventBusProvider.class).in(Scopes.SINGLETON);
    bind(Semaphore.class).annotatedWith(Names.named("JournalSignal")).toInstance(new Semaphore(0));
    install(new FactoryModuleBuilder().build(new TypeLiteral<IOState.Factory<MessageInput>>() {
    }));
    bind(InputRegistry.class).asEagerSingleton();
    bind(OkHttpClient.class).toProvider(OkHttpClientProvider.class).asEagerSingleton();
    bind(MimetypesFileTypeMap.class).toInstance(new MimetypesFileTypeMap());
    bind(ExecutorService.class).annotatedWith(Names.named("proxiedRequestsExecutorService")).toProvider(ProxiedRequestsExecutorService.class).asEagerSingleton();
    bind(FailureHandler.class).annotatedWith(Names.named("fallbackFailureHandler")).to(DefaultFailureHandler.class).asEagerSingleton();
    Multibinder.newSetBinder(binder(), FailureHandler.class);
    OptionalBinder.newOptionalBinder(binder(), FailureHandlingConfiguration.class).setDefault().to(DefaultFailureHandlingConfiguration.class);
    final MapBinder<String, IndexTemplateProvider> indexTemplateProviderBinder = MapBinder.newMapBinder(binder(), String.class, IndexTemplateProvider.class);
    indexTemplateProviderBinder.addBinding(MessageIndexTemplateProvider.MESSAGE_TEMPLATE_TYPE).to(MessageIndexTemplateProvider.class);
    indexTemplateProviderBinder.addBinding(EventIndexTemplateProvider.EVENT_TEMPLATE_TYPE).to(EventIndexTemplateProvider.class);
    serviceBinder().addBinding().to(FailureHandlingService.class).in(Scopes.SINGLETON);
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) DefaultFailureHandler(org.graylog.failure.DefaultFailureHandler) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) DefaultFailureHandler(org.graylog.failure.DefaultFailureHandler) FailureHandler(org.graylog.failure.FailureHandler) FailureHandlingService(org.graylog.failure.FailureHandlingService) MessageInput(org.graylog2.plugin.inputs.MessageInput) Semaphore(java.util.concurrent.Semaphore) InputRegistry(org.graylog2.shared.inputs.InputRegistry) MessageIndexTemplateProvider(org.graylog2.indexer.MessageIndexTemplateProvider) EventIndexTemplateProvider(org.graylog2.indexer.EventIndexTemplateProvider) IndexTemplateProvider(org.graylog2.indexer.IndexTemplateProvider) EventBusProvider(org.graylog2.shared.bindings.providers.EventBusProvider) TypeLiteral(com.google.inject.TypeLiteral) ServiceManagerProvider(org.graylog2.shared.bindings.providers.ServiceManagerProvider) ProxiedRequestsExecutorService(org.graylog2.shared.bindings.providers.ProxiedRequestsExecutorService) IOState(org.graylog2.plugin.IOState) NodeId(org.graylog2.plugin.system.NodeId) OkHttpClientProvider(org.graylog2.shared.bindings.providers.OkHttpClientProvider) ProxiedRequestsExecutorService(org.graylog2.shared.bindings.providers.ProxiedRequestsExecutorService) ExecutorService(java.util.concurrent.ExecutorService) NoopInputBuffer(org.graylog2.shared.buffers.NoopInputBuffer) InputBuffer(org.graylog2.plugin.buffers.InputBuffer) ProcessBuffer(org.graylog2.shared.buffers.ProcessBuffer) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry)

Aggregations

MessageInput (org.graylog2.plugin.inputs.MessageInput)47 Test (org.junit.Test)18 Callable (java.util.concurrent.Callable)17 NotFoundException (org.graylog2.database.NotFoundException)10 Configuration (org.graylog2.plugin.configuration.Configuration)9 ChannelHandler (io.netty.channel.ChannelHandler)8 LinkedHashMap (java.util.LinkedHashMap)8 Input (org.graylog2.inputs.Input)8 MisfireException (org.graylog2.plugin.inputs.MisfireException)7 ChannelHandler (org.jboss.netty.channel.ChannelHandler)7 Timed (com.codahale.metrics.annotation.Timed)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 EventBus (com.google.common.eventbus.EventBus)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 Subscribe (com.google.common.eventbus.Subscribe)4 Produces (javax.ws.rs.Produces)4 IOState (org.graylog2.plugin.IOState)4 LocalMetricRegistry (org.graylog2.plugin.LocalMetricRegistry)4 Extractor (org.graylog2.plugin.inputs.Extractor)4