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