Search in sources :

Example 51 with MessageInput

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

the class IOStateTest method testEqualsSameState.

@Test
public void testEqualsSameState() throws Exception {
    EventBus eventBus = mock(EventBus.class);
    MessageInput messageInput = mock(MessageInput.class);
    IOState<MessageInput> inputState1 = new IOState<>(eventBus, messageInput, IOState.Type.RUNNING);
    IOState<MessageInput> inputState2 = new IOState<>(eventBus, messageInput, IOState.Type.RUNNING);
    assertTrue(inputState1.equals(inputState2));
    assertTrue(inputState2.equals(inputState1));
}
Also used : IOState(org.graylog2.plugin.IOState) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 52 with MessageInput

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

the class FromInput method evaluate.

@Override
public Boolean evaluate(FunctionArgs args, EvaluationContext context) {
    String id = idParam.optional(args, context).orElse("");
    MessageInput input = null;
    if ("".equals(id)) {
        final String name = nameParam.optional(args, context).orElse("");
        for (IOState<MessageInput> messageInputIOState : inputRegistry.getInputStates()) {
            final MessageInput messageInput = messageInputIOState.getStoppable();
            if (messageInput.getTitle().equalsIgnoreCase(name)) {
                input = messageInput;
                break;
            }
        }
        if ("".equals(name)) {
            return null;
        }
    } else {
        final IOState<MessageInput> inputState = inputRegistry.getInputState(id);
        if (inputState != null) {
            input = inputState.getStoppable();
        }
    }
    return input != null && input.getId().equals(context.currentMessage().getSourceInputId());
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 53 with MessageInput

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

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

the class InputEventListener method leaderChanged.

@Subscribe
public void leaderChanged(LeaderChangedEvent event) {
    if (serverStatus.getLifecycle() == Lifecycle.STARTING) {
        LOG.debug("Ignoring LeaderChangedEvent during server startup.");
        return;
    }
    if (leaderElectionService.isLeader()) {
        for (MessageInput input : persistedInputs) {
            final IOState<MessageInput> inputState = inputRegistry.getInputState(input.getId());
            if (input.onlyOnePerCluster() && input.isGlobal() && (inputState == null || inputState.canBeStarted()) && inputLauncher.shouldStartAutomatically(input)) {
                LOG.info("Got leader role. Starting input [{}/{}/{}]", input.getName(), input.getTitle(), input.getId());
                startMessageInput(input);
            }
        }
    } else {
        inputRegistry.getRunningInputs().stream().map(IOState::getStoppable).filter(input -> input.isGlobal() && input.onlyOnePerCluster()).forEach(input -> {
            LOG.info("Lost leader role. Stopping input [{}/{}/{}]", input.getName(), input.getTitle(), input.getId());
            inputDeleted(InputDeleted.create(input.getId()));
        });
    }
}
Also used : InputCreated(org.graylog2.rest.models.system.inputs.responses.InputCreated) Logger(org.slf4j.Logger) InputUpdated(org.graylog2.rest.models.system.inputs.responses.InputUpdated) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) PersistedInputs(org.graylog2.shared.inputs.PersistedInputs) LoggerFactory(org.slf4j.LoggerFactory) ServerStatus(org.graylog2.plugin.ServerStatus) EventBus(com.google.common.eventbus.EventBus) InputLauncher(org.graylog2.shared.inputs.InputLauncher) InputRegistry(org.graylog2.shared.inputs.InputRegistry) Inject(javax.inject.Inject) LeaderChangedEvent(org.graylog2.cluster.leader.LeaderChangedEvent) LeaderElectionService(org.graylog2.cluster.leader.LeaderElectionService) MessageInput(org.graylog2.plugin.inputs.MessageInput) Lifecycle(org.graylog2.plugin.lifecycles.Lifecycle) NodeId(org.graylog2.plugin.system.NodeId) InputDeleted(org.graylog2.rest.models.system.inputs.responses.InputDeleted) Subscribe(com.google.common.eventbus.Subscribe) NotFoundException(org.graylog2.database.NotFoundException) IOState(org.graylog2.plugin.IOState) IOState(org.graylog2.plugin.IOState) MessageInput(org.graylog2.plugin.inputs.MessageInput) Subscribe(com.google.common.eventbus.Subscribe)

Example 55 with MessageInput

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

the class HttpTransport method getCustomChildChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getCustomChildChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
    if (idleWriterTimeout > 0) {
        // Install read timeout handler to close idle connections after a timeout.
        // This avoids dangling HTTP connections when the HTTP client does not close the connection properly.
        // For details see: https://github.com/Graylog2/graylog2-server/issues/3223#issuecomment-270350500
        handlers.put("read-timeout-handler", () -> new ReadTimeoutHandler(idleWriterTimeout, TimeUnit.SECONDS));
    }
    handlers.put("decoder", () -> new HttpRequestDecoder(DEFAULT_MAX_INITIAL_LINE_LENGTH, DEFAULT_MAX_HEADER_SIZE, maxChunkSize));
    handlers.put("decompressor", HttpContentDecompressor::new);
    handlers.put("encoder", HttpResponseEncoder::new);
    handlers.put("aggregator", () -> new HttpObjectAggregator(maxChunkSize));
    handlers.put("http-handler", () -> new HttpHandler(enableCors));
    handlers.putAll(super.getCustomChildChannelHandlers(input));
    return handlers;
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpHandler(org.graylog2.inputs.transports.netty.HttpHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) ChannelHandler(io.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor)

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