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