Search in sources :

Example 31 with MessageInput

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

the class UdpTransport method launch.

@Override
public void launch(final MessageInput input) throws MisfireException {
    try {
        bootstrap = getBootstrap(input);
        final NettyTransportType transportType = nettyTransportConfiguration.getType();
        int numChannels = (transportType == NettyTransportType.EPOLL || transportType == NettyTransportType.KQUEUE) ? workerThreads : 1;
        for (int i = 0; i < numChannels; i++) {
            LOG.debug("Starting channel on {}", socketAddress);
            bootstrap.bind(socketAddress).addListener(new InputLaunchListener(channels, input, getRecvBufferSize())).syncUninterruptibly();
        }
    } catch (Exception e) {
        throw new MisfireException(e);
    }
}
Also used : MisfireException(org.graylog2.plugin.inputs.MisfireException) NettyTransportType(org.graylog2.inputs.transports.netty.NettyTransportType) MisfireException(org.graylog2.plugin.inputs.MisfireException)

Example 32 with MessageInput

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

the class HttpPollTransport method doLaunch.

@Override
public void doLaunch(final MessageInput input) throws MisfireException {
    serverStatus.awaitRunning(() -> lifecycleStateChange(Lifecycle.RUNNING));
    // listen for lifecycle changes
    serverEventBus.register(this);
    final Map<String, String> headers = parseHeaders(configuration.getString(CK_HEADERS));
    // figure out a reasonable remote address
    final String url = configuration.getString(CK_URL);
    final InetSocketAddress remoteAddress;
    InetSocketAddress remoteAddress1;
    try {
        final URL url1 = new URL(url);
        final int port = url1.getPort();
        remoteAddress1 = new InetSocketAddress(url1.getHost(), port != -1 ? port : 80);
    } catch (MalformedURLException e) {
        remoteAddress1 = null;
    }
    remoteAddress = remoteAddress1;
    final Runnable task = () -> {
        if (paused) {
            LOG.debug("Message processing paused, not polling HTTP resource {}.", url);
            return;
        }
        if (isThrottled()) {
            // this transport won't block, but we can simply skip this iteration
            LOG.debug("Not polling HTTP resource {} because we are throttled.", url);
            return;
        }
        final Request.Builder requestBuilder = new Request.Builder().get().url(url).headers(Headers.of(headers));
        try (final Response r = httpClient.newCall(requestBuilder.build()).execute()) {
            if (!r.isSuccessful()) {
                LOG.error("Expected successful HTTP status code [2xx], got " + r.code());
                return;
            }
            input.processRawMessage(new RawMessage(r.body().bytes(), remoteAddress));
        } catch (IOException e) {
            LOG.error("Could not fetch HTTP resource at " + url, e);
        }
    };
    scheduledFuture = scheduler.scheduleAtFixedRate(task, 0, configuration.getInt(CK_INTERVAL), TimeUnit.valueOf(configuration.getString(CK_TIMEUNIT)));
}
Also used : Response(okhttp3.Response) MalformedURLException(java.net.MalformedURLException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) RawMessage(org.graylog2.plugin.journal.RawMessage) URL(java.net.URL)

Example 33 with MessageInput

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

the class AmqpTransport method doLaunch.

@Override
public void doLaunch(MessageInput input) throws MisfireException {
    int heartbeatTimeout = ConnectionFactory.DEFAULT_HEARTBEAT;
    if (configuration.intIsSet(CK_HEARTBEAT_TIMEOUT)) {
        heartbeatTimeout = configuration.getInt(CK_HEARTBEAT_TIMEOUT);
        if (heartbeatTimeout < 0) {
            LOG.warn("AMQP heartbeat interval must not be negative ({}), using default timeout ({}).", heartbeatTimeout, ConnectionFactory.DEFAULT_HEARTBEAT);
            heartbeatTimeout = ConnectionFactory.DEFAULT_HEARTBEAT;
        }
    }
    consumer = new AmqpConsumer(configuration.getString(CK_HOSTNAME), configuration.getInt(CK_PORT), configuration.getString(CK_VHOST), configuration.getString(CK_USERNAME), configuration.getString(CK_PASSWORD), configuration.getInt(CK_PREFETCH), configuration.getString(CK_QUEUE), configuration.getString(CK_EXCHANGE), configuration.getBoolean(CK_EXCHANGE_BIND), configuration.getString(CK_ROUTING_KEY), configuration.getInt(CK_PARALLEL_QUEUES), configuration.getBoolean(CK_TLS), configuration.getBoolean(CK_REQUEUE_INVALID_MESSAGES), heartbeatTimeout, input, scheduler, this);
    eventBus.register(this);
    try {
        consumer.run();
    } catch (IOException e) {
        eventBus.unregister(this);
        throw new MisfireException("Could not launch AMQP consumer.", e);
    }
}
Also used : MisfireException(org.graylog2.plugin.inputs.MisfireException) IOException(java.io.IOException)

Example 34 with MessageInput

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

the class BeatsTransportTest method customChildChannelHandlersContainBeatsHandler.

@Test
public void customChildChannelHandlersContainBeatsHandler() {
    final NettyTransportConfiguration nettyTransportConfiguration = new NettyTransportConfiguration("nio", "jdk", 1);
    final EventLoopGroupFactory eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
    final BeatsTransport transport = new BeatsTransport(Configuration.EMPTY_CONFIGURATION, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, new ThroughputCounter(eventLoopGroup), new LocalMetricRegistry(), tlsConfiguration);
    final MessageInput input = mock(MessageInput.class);
    assertThat(transport.getCustomChildChannelHandlers(input)).containsKey("beats");
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) MessageInput(org.graylog2.plugin.inputs.MessageInput) EventLoopGroupFactory(org.graylog2.inputs.transports.netty.EventLoopGroupFactory) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Test(org.junit.Test)

Example 35 with MessageInput

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

the class IOStateTest method testNotEqualIfDifferentInput.

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

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