Search in sources :

Example 11 with MessageInput

use of org.graylog2.plugin.inputs.MessageInput 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 12 with MessageInput

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

the class BundleImporter method deleteCreatedInputs.

private void deleteCreatedInputs() throws NotFoundException {
    for (Map.Entry<String, MessageInput> entry : createdInputs.entrySet()) {
        final String inputId = entry.getKey();
        final MessageInput messageInput = entry.getValue();
        LOG.debug("Terminating message input {}", inputId);
        inputRegistry.remove(messageInput);
        final org.graylog2.inputs.Input input = inputService.find(messageInput.getId());
        inputService.destroy(input);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 13 with MessageInput

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

the class BundleImporter method createInputs.

private void createInputs(final String bundleId, final Set<Input> inputs, final String userName) throws org.graylog2.plugin.inputs.Extractor.ReservedFieldException, org.graylog2.ConfigurationException, NoSuchInputTypeException, ValidationException, ExtractorFactory.NoSuchExtractorException, NotFoundException, ConfigurationException {
    for (final Input input : inputs) {
        final MessageInput messageInput = createMessageInput(bundleId, input, userName);
        createdInputs.put(messageInput.getId(), messageInput);
        // Launch input. (this will run async and clean up itself in case of an error.)
        inputLauncher.launch(messageInput);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 14 with MessageInput

use of org.graylog2.plugin.inputs.MessageInput 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)

Example 15 with MessageInput

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

the class InputFacade method decode.

private NativeEntity<InputWithExtractors> decode(EntityV1 entity, Map<String, ValueReference> parameters, String username) {
    final InputEntity inputEntity = objectMapper.convertValue(entity.data(), InputEntity.class);
    final Map<String, ValueReference> staticFields = inputEntity.staticFields();
    final MessageInput messageInput;
    try {
        messageInput = createMessageInput(inputEntity.title().asString(parameters), inputEntity.type().asString(parameters), inputEntity.global().asBoolean(parameters), toValueMap(inputEntity.configuration(), parameters), username);
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create input", e);
    }
    final Input input;
    try {
        input = inputService.find(messageInput.getPersistId());
    } catch (NotFoundException e) {
        throw new RuntimeException("Couldn't find persisted input", e);
    }
    try {
        addStaticFields(input, messageInput, staticFields, parameters);
    } catch (ValidationException e) {
        throw new RuntimeException("Couldn't add static fields to input", e);
    }
    final List<Extractor> extractors;
    try {
        extractors = createExtractors(input, inputEntity.extractors(), username, parameters);
    } catch (Exception e) {
        throw new RuntimeException("Couldn't create extractors", e);
    }
    return NativeEntity.create(entity.id(), input.getId(), TYPE_V1, input.getTitle(), InputWithExtractors.create(input, extractors));
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) Extractor(org.graylog2.plugin.inputs.Extractor) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) ValidationException(org.graylog2.plugin.database.ValidationException) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference)

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