Search in sources :

Example 31 with Configuration

use of org.graylog2.plugin.configuration.Configuration 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);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(org.jboss.netty.channel.ChannelHandler) File(java.io.File) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 32 with Configuration

use of org.graylog2.plugin.configuration.Configuration 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);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(org.jboss.netty.channel.ChannelHandler) File(java.io.File) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 33 with Configuration

use of org.graylog2.plugin.configuration.Configuration 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");
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(org.jboss.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 34 with Configuration

use of org.graylog2.plugin.configuration.Configuration 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);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(org.jboss.netty.channel.ChannelHandler) File(java.io.File) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 35 with Configuration

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

the class BundleImporter method createMessageInput.

private MessageInput createMessageInput(final String bundleId, final Input inputDescription, final String userName) throws NoSuchInputTypeException, ConfigurationException, ValidationException, NotFoundException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, org.graylog2.plugin.inputs.Extractor.ReservedFieldException {
    final Configuration inputConfig = new Configuration(inputDescription.getConfiguration());
    final DateTime createdAt = Tools.nowUTC();
    final MessageInput messageInput = messageInputFactory.create(inputDescription.getType(), inputConfig);
    messageInput.setTitle(inputDescription.getTitle());
    messageInput.setGlobal(inputDescription.isGlobal());
    messageInput.setCreatorUserId(userName);
    messageInput.setCreatedAt(createdAt);
    messageInput.setContentPack(bundleId);
    messageInput.checkConfiguration();
    // Don't run if exclusive and another instance is already running.
    if (messageInput.isExclusive() && inputRegistry.hasTypeRunning(messageInput.getClass())) {
        LOG.error("Input type <{}> of input <{}> is exclusive and already has input running.", messageInput.getClass(), messageInput.getTitle());
    }
    final String id = inputDescription.getId();
    final org.graylog2.inputs.Input mongoInput;
    if (id == null) {
        mongoInput = inputService.create(buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
    } else {
        mongoInput = inputService.create(id, buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
    }
    // Persist input.
    final String persistId = inputService.save(mongoInput);
    messageInput.setPersistId(persistId);
    messageInput.initialize();
    addStaticFields(messageInput, inputDescription.getStaticFields());
    addExtractors(messageInput, inputDescription.getExtractors(), userName);
    return messageInput;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) DateTime(org.joda.time.DateTime)

Aggregations

Test (org.junit.Test)34 Configuration (org.graylog2.plugin.configuration.Configuration)29 ApiOperation (io.swagger.annotations.ApiOperation)24 Timed (com.codahale.metrics.annotation.Timed)23 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)17 Consumes (javax.ws.rs.Consumes)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Stream (org.graylog2.plugin.streams.Stream)13 ApiResponses (io.swagger.annotations.ApiResponses)12 PUT (javax.ws.rs.PUT)11 ValidationException (org.graylog2.plugin.database.ValidationException)11 DateTime (org.joda.time.DateTime)11 Produces (javax.ws.rs.Produces)10 Configuration (org.graylog2.Configuration)10 POST (javax.ws.rs.POST)9 EmailConfiguration (org.graylog2.configuration.EmailConfiguration)9 URI (java.net.URI)8