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);
}
}
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)));
}
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);
}
}
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");
}
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));
}
Aggregations