Search in sources :

Example 16 with MessageInput

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

the class InputFacade method createMessageInput.

private MessageInput createMessageInput(final String title, final String type, final boolean global, final Map<String, Object> configuration, final String username) throws NoSuchInputTypeException, ConfigurationException, ValidationException {
    final Configuration inputConfig = new Configuration(configuration);
    final DateTime createdAt = Tools.nowUTC();
    final MessageInput messageInput = messageInputFactory.create(type, inputConfig);
    messageInput.setTitle(title);
    messageInput.setGlobal(global);
    messageInput.setCreatorUserId(username);
    messageInput.setCreatedAt(createdAt);
    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 Input mongoInput = inputService.create(buildMongoDbInput(title, type, global, configuration, username, createdAt));
    // Persist input
    final String persistId = inputService.save(mongoInput);
    messageInput.setPersistId(persistId);
    messageInput.initialize();
    return messageInput;
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) DateTime(org.joda.time.DateTime)

Example 17 with MessageInput

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

the class InputSetupService method shutDown.

@Override
protected void shutDown() throws Exception {
    LOG.debug("Stopping InputSetupService");
    eventBus.unregister(this);
    for (IOState<MessageInput> state : inputRegistry.getRunningInputs()) {
        MessageInput input = state.getStoppable();
        LOG.info("Attempting to close input <{}> [{}].", input.getUniqueReadableId(), input.getName());
        Stopwatch s = Stopwatch.createStarted();
        try {
            input.stop();
            LOG.info("Input <{}> closed. Took [{}ms]", input.getUniqueReadableId(), s.elapsed(TimeUnit.MILLISECONDS));
        } catch (Exception e) {
            LOG.error("Unable to stop input <{}> [{}]: " + e.getMessage(), input.getUniqueReadableId(), input.getName());
        } finally {
            s.stop();
        }
    }
    LOG.debug("Stopped InputSetupService");
}
Also used : Stopwatch(com.google.common.base.Stopwatch) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 18 with MessageInput

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

the class InputEventListener method inputUpdated.

@Subscribe
public void inputUpdated(InputUpdated inputUpdatedEvent) {
    final String inputId = inputUpdatedEvent.id();
    LOG.debug("Input updated: {}", inputId);
    final Input input;
    try {
        input = inputService.find(inputId);
    } catch (NotFoundException e) {
        LOG.warn("Received InputUpdated event but could not find input {}", inputId, e);
        return;
    }
    final boolean startInput;
    final IOState<MessageInput> inputState = inputRegistry.getInputState(inputId);
    if (inputState != null) {
        startInput = inputState.getState() == IOState.Type.RUNNING;
        inputRegistry.remove(inputState);
    } else {
        startInput = false;
    }
    if (startInput && (input.isGlobal() || this.nodeId.toString().equals(input.getNodeId()))) {
        startInput(input);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) MessageInput(org.graylog2.plugin.inputs.MessageInput) Subscribe(com.google.common.eventbus.Subscribe)

Example 19 with MessageInput

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

the class InputEventListener method inputCreated.

@Subscribe
public void inputCreated(InputCreated inputCreatedEvent) {
    final String inputId = inputCreatedEvent.id();
    LOG.debug("Input created: {}", inputId);
    final Input input;
    try {
        input = inputService.find(inputId);
    } catch (NotFoundException e) {
        LOG.warn("Received InputCreated event but could not find input {}", inputId, e);
        return;
    }
    final IOState<MessageInput> inputState = inputRegistry.getInputState(inputId);
    if (inputState != null) {
        inputRegistry.remove(inputState);
    }
    if (input.isGlobal() || this.nodeId.toString().equals(input.getNodeId())) {
        startInput(input);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) MessageInput(org.graylog2.plugin.inputs.MessageInput) Subscribe(com.google.common.eventbus.Subscribe)

Example 20 with MessageInput

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

the class InputStateListener method inputStateChanged.

@Subscribe
public void inputStateChanged(IOStateChangedEvent<MessageInput> event) {
    final IOState<MessageInput> state = event.changedState();
    final MessageInput input = state.getStoppable();
    switch(event.newState()) {
        case FAILED:
            activityWriter.write(new Activity(state.getDetailedMessage(), InputRegistry.class));
            Notification notification = notificationService.buildNow();
            notification.addType(Notification.Type.INPUT_FAILED_TO_START).addSeverity(Notification.Severity.NORMAL);
            notification.addNode(serverStatus.getNodeId().toString());
            notification.addDetail("input_id", input.getId());
            notification.addDetail("reason", state.getDetailedMessage());
            notificationService.publishIfFirst(notification);
            break;
        case RUNNING:
            notificationService.fixed(Notification.Type.NO_INPUT_RUNNING);
        // fall through
        default:
            final String msg = "Input [" + input.getName() + "/" + input.getId() + "] is now " + event.newState().toString();
            activityWriter.write(new Activity(msg, InputStateListener.class));
            break;
    }
    LOG.debug("Input State of [{}/{}] changed: {} -> {}", input.getTitle(), input.getId(), event.oldState(), event.newState());
    LOG.info("Input [{}/{}] is now {}", input.getName(), input.getId(), event.newState());
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) Activity(org.graylog2.shared.system.activities.Activity) InputRegistry(org.graylog2.shared.inputs.InputRegistry) Notification(org.graylog2.notifications.Notification) Subscribe(com.google.common.eventbus.Subscribe)

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