use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class NettyTransport method getChannelHandlers.
/**
* Subclasses can override this to add additional {@link ChannelHandler channel handlers} to the
* Netty {@link ChannelPipeline} to support additional features.
*
* Some common use cases are to add connection counters or traffic shapers.
*
* @param input The {@link MessageInput} for which these channel handlers are being added
* @return list of initial {@link ChannelHandler channel handlers} to add to the Netty {@link ChannelPipeline channel pipeline}
*/
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChannelHandlers(final MessageInput input) {
LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList = new LinkedHashMap<>();
handlerList.put("exception-logger", () -> new ExceptionLoggingChannelHandler(input, log));
handlerList.put("packet-meta-dumper", () -> new PacketInformationDumper(input));
handlerList.put("output-failure-logger", () -> PromiseFailureHandler.INSTANCE);
return handlerList;
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class InputsResource method create.
@POST
@Timed
@ApiOperation(value = "Launch input on this node", response = InputCreated.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input type registered"), @ApiResponse(code = 400, message = "Missing or invalid configuration"), @ApiResponse(code = 400, message = "Type is exclusive and already has input running") })
@RequiresPermissions(RestPermissions.INPUTS_CREATE)
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_CREATE)
public Response create(@ApiParam(name = "JSON body", required = true) @Valid @NotNull InputCreateRequest lr) throws ValidationException {
try {
// TODO Configuration type values need to be checked. See ConfigurationMapConverter.convertValues()
final MessageInput messageInput = messageInputFactory.create(lr, getCurrentUser().getName(), lr.node());
messageInput.checkConfiguration();
final Input input = this.inputService.create(messageInput.asMap());
final String newId = inputService.save(input);
final URI inputUri = getUriBuilderToSelf().path(InputsResource.class).path("{inputId}").build(newId);
return Response.created(inputUri).entity(InputCreated.create(newId)).build();
} catch (NoSuchInputTypeException e) {
LOG.error("There is no such input type registered.", e);
throw new NotFoundException("There is no such input type registered.", e);
} catch (ConfigurationException e) {
LOG.error("Missing or invalid input configuration.", e);
throw new BadRequestException("Missing or invalid input configuration.", e);
}
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class StaticFieldsResource method create.
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add a static field to an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "Field/Key is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStaticFieldRequest csfr) throws NotFoundException, ValidationException {
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
final MessageInput input = persistedInputs.get(inputId);
if (input == null) {
final String msg = "Input <" + inputId + "> not found.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
// Check if key is a valid message key.
if (!Message.validKey(csfr.key())) {
final String msg = "Invalid key: [" + csfr.key() + "]";
LOG.error(msg);
throw new BadRequestException(msg);
}
if (Message.RESERVED_FIELDS.contains(csfr.key()) && !Message.RESERVED_SETTABLE_FIELDS.contains(csfr.key())) {
final String message = "Cannot add static field. Field [" + csfr.key() + "] is reserved.";
LOG.error(message);
throw new BadRequestException(message);
}
input.addStaticField(csfr.key(), csfr.value());
final Input mongoInput = inputService.find(input.getPersistId());
inputService.addStaticField(mongoInput, csfr.key(), csfr.value());
final String msg = "Added static field [" + csfr.key() + "] to input <" + inputId + ">.";
LOG.info(msg);
activityWriter.write(new Activity(msg, StaticFieldsResource.class));
final URI inputUri = getUriBuilderToSelf().path(InputsResource.class).path("{inputId}").build(mongoInput.getId());
return Response.created(inputUri).build();
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class StaticFieldsResource method delete.
@DELETE
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Remove static field of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 404, message = "No such static field.") })
@Path("/{key}")
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_DELETE)
public void delete(@ApiParam(name = "Key", required = true) @PathParam("key") String key, @ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws NotFoundException {
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
MessageInput input = persistedInputs.get(inputId);
if (input == null) {
final String msg = "Input <" + inputId + "> not found.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
if (!input.getStaticFields().containsKey(key)) {
final String msg = "No such static field [" + key + "] on input <" + inputId + ">.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
input.getStaticFields().remove(key);
Input mongoInput = inputService.find(input.getPersistId());
inputService.removeStaticField(mongoInput, key);
final String msg = "Removed static field [" + key + "] of input <" + inputId + ">.";
LOG.info(msg);
activityWriter.write(new Activity(msg, StaticFieldsResource.class));
}
use of org.graylog2.plugin.inputs.MessageInput in project graylog2-server by Graylog2.
the class GenericBindings method configure.
@Override
protected void configure() {
// must not be a singleton!
bind(LocalMetricRegistry.class).in(Scopes.NO_SCOPE);
install(new FactoryModuleBuilder().build(DecodingProcessor.Factory.class));
bind(ProcessBuffer.class).asEagerSingleton();
if (isMigrationCommand) {
bind(InputBuffer.class).to(NoopInputBuffer.class);
} else {
bind(InputBuffer.class).to(InputBufferImpl.class);
}
bind(NodeId.class).toProvider(NodeIdProvider.class);
if (!isMigrationCommand) {
bind(ServiceManager.class).toProvider(ServiceManagerProvider.class).asEagerSingleton();
}
bind(ThroughputCounter.class);
bind(EventBus.class).toProvider(EventBusProvider.class).in(Scopes.SINGLETON);
bind(Semaphore.class).annotatedWith(Names.named("JournalSignal")).toInstance(new Semaphore(0));
install(new FactoryModuleBuilder().build(new TypeLiteral<IOState.Factory<MessageInput>>() {
}));
bind(InputRegistry.class).asEagerSingleton();
bind(OkHttpClient.class).toProvider(OkHttpClientProvider.class).asEagerSingleton();
bind(MimetypesFileTypeMap.class).toInstance(new MimetypesFileTypeMap());
bind(ExecutorService.class).annotatedWith(Names.named("proxiedRequestsExecutorService")).toProvider(ProxiedRequestsExecutorService.class).asEagerSingleton();
bind(FailureHandler.class).annotatedWith(Names.named("fallbackFailureHandler")).to(DefaultFailureHandler.class).asEagerSingleton();
Multibinder.newSetBinder(binder(), FailureHandler.class);
OptionalBinder.newOptionalBinder(binder(), FailureHandlingConfiguration.class).setDefault().to(DefaultFailureHandlingConfiguration.class);
final MapBinder<String, IndexTemplateProvider> indexTemplateProviderBinder = MapBinder.newMapBinder(binder(), String.class, IndexTemplateProvider.class);
indexTemplateProviderBinder.addBinding(MessageIndexTemplateProvider.MESSAGE_TEMPLATE_TYPE).to(MessageIndexTemplateProvider.class);
indexTemplateProviderBinder.addBinding(EventIndexTemplateProvider.EVENT_TEMPLATE_TYPE).to(EventIndexTemplateProvider.class);
serviceBinder().addBinding().to(FailureHandlingService.class).in(Scopes.SINGLETON);
}
Aggregations