use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class NettyTransport method getBaseChannelHandlers.
/**
* Subclasses can override this to add additional ChannelHandlers to the pipeline to support additional features.
* <p/>
* Some common use cases are to add SSL/TLS, connection counters or throttling traffic shapers.
*
* @param input
* @return the list of initial channelhandlers to add to the {@link org.jboss.netty.channel.ChannelPipelineFactory}
*/
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(final MessageInput input) {
LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = Maps.newLinkedHashMap();
handlerList.put("exception-logger", new Callable<ChannelHandler>() {
@Override
public ChannelHandler call() throws Exception {
return new SimpleChannelUpstreamHandler() {
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
if ("Connection reset by peer".equals(e.getCause().getMessage())) {
log.trace("{} in Input [{}/{}] (channel {})", e.getCause().getMessage(), input.getName(), input.getId(), e.getChannel());
} else {
log.error("Error in Input [{}/{}] (channel {})", input.getName(), input.getId(), e.getChannel(), e.getCause());
}
super.exceptionCaught(ctx, e);
}
};
}
});
handlerList.put("packet-meta-dumper", new Callable<ChannelHandler>() {
@Override
public ChannelHandler call() throws Exception {
return new PacketInformationDumper(input);
}
});
handlerList.put("traffic-counter", Callables.returning(throughputCounter));
return handlerList;
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersFailsIfTempDirDoesNotExist.
@Test
public void getBaseChannelHandlersFailsIfTempDirDoesNotExist() throws IOException {
final File tmpDir = temporaryFolder.newFolder();
assumeTrue(tmpDir.delete());
System.setProperty("java.io.tmpdir", tmpDir.getAbsolutePath());
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Couldn't write to temporary directory: " + tmpDir.getAbsolutePath());
transport.getBaseChannelHandlers(input);
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersFailsIfTempDirIsNotWritable.
@Test
public void getBaseChannelHandlersFailsIfTempDirIsNotWritable() throws IOException {
final File tmpDir = temporaryFolder.newFolder();
assumeTrue(tmpDir.setWritable(false));
assumeFalse(tmpDir.canWrite());
System.setProperty("java.io.tmpdir", tmpDir.getAbsolutePath());
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Couldn't write to temporary directory: " + tmpDir.getAbsolutePath());
transport.getBaseChannelHandlers(input);
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersGeneratesSelfSignedCertificates.
@Test
public void getBaseChannelHandlersGeneratesSelfSignedCertificates() {
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
final MessageInput input = mock(MessageInput.class);
assertThat(transport.getBaseChannelHandlers(input)).containsKey("tls");
}
use of org.graylog2.plugin.inputs.util.ThroughputCounter in project graylog2-server by Graylog2.
the class AbstractTcpTransportTest method getBaseChannelHandlersFailsIfTempDirIsNoDirectory.
@Test
public void getBaseChannelHandlersFailsIfTempDirIsNoDirectory() throws IOException {
final File file = temporaryFolder.newFile();
assumeTrue(file.isFile());
System.setProperty("java.io.tmpdir", file.getAbsolutePath());
final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "localhost", "port", 12345, "tls_enable", true));
final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, bossPool, workerPool, connectionCounter) {
@Override
protected Bootstrap getBootstrap() {
return super.getBootstrap();
}
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
return super.getBaseChannelHandlers(input);
}
};
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Couldn't write to temporary directory: " + file.getAbsolutePath());
transport.getBaseChannelHandlers(input);
}
Aggregations