Search in sources :

Example 86 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class AbstractTcpTransportTest method getChildChannelHandlersFailsIfTempDirIsNoDirectory.

@Test
public void getChildChannelHandlersFailsIfTempDirIsNoDirectory() 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, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, tlsConfiguration) {
    };
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Couldn't write to temporary directory: " + file.getAbsolutePath());
    transport.getChildChannelHandlers(input);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) File(java.io.File) Test(org.junit.Test)

Example 87 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class AbstractTcpTransportTest method testTrafficCounter.

@Test
@Ignore("Disabled test due to being unreliable. For details see https://github.com/Graylog2/graylog2-server/issues/4702.")
public void testTrafficCounter() throws Exception {
    final Configuration configuration = new Configuration(ImmutableMap.of("bind_address", "127.0.0.1", "port", 0));
    final AbstractTcpTransport transport = new AbstractTcpTransport(configuration, throughputCounter, localRegistry, eventLoopGroup, eventLoopGroupFactory, nettyTransportConfiguration, tlsConfiguration) {
    };
    transport.launch(input);
    await().atMost(5, TimeUnit.SECONDS).until(() -> transport.getLocalAddress() != null);
    final InetSocketAddress localAddress = (InetSocketAddress) transport.getLocalAddress();
    assertThat(localAddress).isNotNull();
    final ChannelFuture channelFuture = clientChannel(localAddress.getHostString(), localAddress.getPort());
    channelFuture.channel().writeAndFlush(Unpooled.copiedBuffer(new byte[1024])).syncUninterruptibly();
    channelFuture.channel().writeAndFlush(Unpooled.copiedBuffer(new byte[1024])).addListener(ChannelFutureListener.CLOSE).syncUninterruptibly();
    // Wait 1s so that the cumulative throughput can be calculated
    Thread.sleep(1000L);
    assertThat(throughputCounter.gauges().get(ThroughputCounter.READ_BYTES_TOTAL).getValue()).isEqualTo(2048L);
    assertThat(throughputCounter.gauges().get(ThroughputCounter.READ_BYTES_1_SEC).getValue()).isEqualTo(2048L);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Configuration(org.graylog2.plugin.configuration.Configuration) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) NettyTransportConfiguration(org.graylog2.inputs.transports.NettyTransportConfiguration) InetSocketAddress(java.net.InetSocketAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 88 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class MessageOutputFactoryTest method testNonExistentOutputType.

@Test(expected = IllegalArgumentException.class)
public void testNonExistentOutputType() throws MessageOutputConfigurationException {
    final String outputType = "non.existent";
    final Output output = mock(Output.class);
    when(output.getType()).thenReturn(outputType);
    final Stream stream = mock(Stream.class);
    final Configuration configuration = mock(Configuration.class);
    messageOutputFactory.fromStreamOutput(output, stream, configuration);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 89 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class InputFacadeTest method createNativeEntity.

@Test
@Ignore("Doesn't work without massive amount of mocks")
public void createNativeEntity() {
    final Map<String, Object> configuration = new HashMap<>();
    configuration.put("override_source", null);
    configuration.put("recv_buffer_size", 262144);
    configuration.put("bind_address", "127.0.0.1");
    configuration.put("port", 5555);
    configuration.put("number_worker_threads", 8);
    final Entity entity = EntityV1.builder().id(ModelId.of("5acc84f84b900a4ff290d9a7")).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(InputEntity.create(ValueReference.of("Local Raw UDP"), ReferenceMapUtils.toReferenceMap(configuration), Collections.emptyMap(), ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"), ValueReference.of(false), Collections.emptyList()), JsonNode.class)).build();
    final NativeEntity<InputWithExtractors> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    final InputWithExtractors inputWithExtractors = nativeEntity.entity();
    final Input savedInput = inputWithExtractors.input();
    final String savedId = savedInput.getId();
    assertThat(nativeEntity.descriptor()).isEqualTo(EntityDescriptor.create(savedId, ModelTypes.INPUT_V1));
    assertThat(savedInput.getTitle()).isEqualTo("Local Raw UDP");
    assertThat(savedInput.getType()).isEqualTo("org.graylog2.inputs.raw.udp.RawUDPInput");
    assertThat(savedInput.isGlobal()).isFalse();
    assertThat(savedInput.getContentPack()).isNull();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Input(org.graylog2.inputs.Input) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 90 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class UdpTransportTest method setUp.

@Before
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void setUp() throws Exception {
    eventLoopGroupFactory = new EventLoopGroupFactory(nettyTransportConfiguration);
    localMetricRegistry = new LocalMetricRegistry();
    eventLoopGroup = eventLoopGroupFactory.create(1, localMetricRegistry, "test");
    throughputCounter = new ThroughputCounter(eventLoopGroup);
    udpTransport = new UdpTransport(CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, localMetricRegistry);
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) EventLoopGroupFactory(org.graylog2.inputs.transports.netty.EventLoopGroupFactory) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Aggregations

Test (org.junit.Test)67 Configuration (org.graylog2.plugin.configuration.Configuration)46 Configuration (org.apache.commons.configuration2.Configuration)35 ApiOperation (io.swagger.annotations.ApiOperation)31 Timed (com.codahale.metrics.annotation.Timed)23 AuditEvent (org.graylog2.audit.jersey.AuditEvent)23 Path (javax.ws.rs.Path)22 BadRequestException (javax.ws.rs.BadRequestException)21 MessageInput (org.graylog2.plugin.inputs.MessageInput)18 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)17 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)15 Stream (org.graylog2.plugin.streams.Stream)15 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)14 File (java.io.File)14 Consumes (javax.ws.rs.Consumes)14 DateTime (org.joda.time.DateTime)14 POST (javax.ws.rs.POST)13 Produces (javax.ws.rs.Produces)13 Configuration (org.graylog2.Configuration)13 ApiResponses (io.swagger.annotations.ApiResponses)12