Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.graylog2.plugin.PluginModule Maven / Gradle / Ivy
/**
* This file is part of Graylog.
*
* Graylog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see .
*/
package org.graylog2.plugin;
import com.google.common.util.concurrent.Service;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import org.graylog.events.fields.providers.FieldValueProvider;
import org.graylog.events.notifications.EventNotification;
import org.graylog.events.notifications.EventNotificationConfig;
import org.graylog.events.processor.EventProcessor;
import org.graylog.events.processor.EventProcessorConfig;
import org.graylog.events.processor.EventProcessorParameters;
import org.graylog.events.processor.storage.EventStorageHandler;
import org.graylog.scheduler.Job;
import org.graylog.scheduler.JobDefinitionConfig;
import org.graylog.scheduler.JobSchedule;
import org.graylog.scheduler.JobTriggerData;
import org.graylog2.audit.AuditEventType;
import org.graylog2.audit.PluginAuditEventTypes;
import org.graylog2.audit.formatter.AuditEventFormatter;
import org.graylog2.contentpacks.constraints.ConstraintChecker;
import org.graylog2.contentpacks.facades.EntityFacade;
import org.graylog2.contentpacks.model.ModelType;
import org.graylog2.migrations.Migration;
import org.graylog2.plugin.alarms.AlertCondition;
import org.graylog2.plugin.alarms.callbacks.AlarmCallback;
import org.graylog2.plugin.dashboards.widgets.WidgetStrategy;
import org.graylog2.plugin.filters.MessageFilter;
import org.graylog2.plugin.indexer.retention.RetentionStrategy;
import org.graylog2.plugin.indexer.rotation.RotationStrategy;
import org.graylog2.plugin.inject.Graylog2Module;
import org.graylog2.plugin.inputs.MessageInput;
import org.graylog2.plugin.inputs.codecs.Codec;
import org.graylog2.plugin.inputs.transports.Transport;
import org.graylog2.plugin.messageprocessors.MessageProcessor;
import org.graylog2.plugin.outputs.MessageOutput;
import org.graylog2.plugin.periodical.Periodical;
import org.graylog2.plugin.rest.PluginRestResource;
import org.graylog2.plugin.security.PasswordAlgorithm;
import org.graylog2.plugin.security.PluginPermissions;
import javax.ws.rs.ext.ExceptionMapper;
import java.util.Collections;
import java.util.Set;
public abstract class PluginModule extends Graylog2Module {
public Set getConfigBeans() {
return Collections.emptySet();
}
protected void addMessageInput(Class messageInputClass) {
installInput(inputsMapBinder(), messageInputClass);
}
protected void addMessageInput(Class messageInputClass,
Class> factoryClass) {
installInput(inputsMapBinder(), messageInputClass, factoryClass);
}
protected void addMessageFilter(Class messageFilterClass) {
Multibinder messageInputs = Multibinder.newSetBinder(binder(), MessageFilter.class);
messageInputs.addBinding().to(messageFilterClass);
}
protected void addPeriodical(Class periodicalClass) {
Multibinder periodicalBinder = Multibinder.newSetBinder(binder(), Periodical.class);
periodicalBinder.addBinding().to(periodicalClass);
}
protected void addRotationStrategy(Class rotationStrategyClass) {
installRotationStrategy(rotationStrategiesMapBinder(), rotationStrategyClass);
}
protected void addRetentionStrategy(Class retentionStrategyClass) {
installRetentionStrategy(retentionStrategyMapBinder(), retentionStrategyClass);
}
protected void addAlarmCallback(Class alarmCallbackClass) {
Multibinder alarmCallbackInstanceBinder = Multibinder.newSetBinder(binder(), AlarmCallback.class);
alarmCallbackInstanceBinder.addBinding().to(alarmCallbackClass);
TypeLiteral> type = new TypeLiteral>() {
};
Multibinder> alarmCallbackBinder = Multibinder.newSetBinder(binder(), type);
alarmCallbackBinder.addBinding().toInstance(alarmCallbackClass);
}
protected void addInitializer(Class initializerClass) {
Multibinder serviceBinder = serviceBinder();
serviceBinder.addBinding().to(initializerClass);
}
// This should only be used by plugins that have been built before Graylog 3.0.1.
// See comments in MessageOutput.Factory and MessageOutput.Factory2 for details
protected void addMessageOutput(Class messageOutputClass) {
installOutput(outputsMapBinder(), messageOutputClass);
}
// This should only be used by plugins that have been built before Graylog 3.0.1.
// See comments in MessageOutput.Factory and MessageOutput.Factory2 for details
protected void addMessageOutput(Class messageOutputClass,
Class> factory) {
installOutput(outputsMapBinder(), messageOutputClass, factory);
}
// This should be used by plugins that have been built for 3.0.1 or later.
// See comments in MessageOutput.Factory and MessageOutput.Factory2 for details
protected void addMessageOutput2(Class messageOutputClass,
Class> factory) {
installOutput2(outputsMapBinder2(), messageOutputClass, factory);
}
protected void addRestResource(Class restResourceClass) {
MapBinder> pluginRestResourceMapBinder =
MapBinder.newMapBinder(binder(), new TypeLiteral() {},
new TypeLiteral>() {})
.permitDuplicates();
pluginRestResourceMapBinder.addBinding(this.getClass().getPackage().getName()).toInstance(restResourceClass);
}
protected void addJerseyExceptionMapper(Class exceptionMapperClass) {
jerseyExceptionMapperBinder().addBinding().toInstance(exceptionMapperClass);
}
protected void addConfigBeans() {
final Multibinder pluginConfigBeans = Multibinder.newSetBinder(binder(), PluginConfigBean.class);
for (PluginConfigBean pluginConfigBean : getConfigBeans()) {
pluginConfigBeans.addBinding().toInstance(pluginConfigBean);
}
}
protected void addTransport(String name, Class transportClass) {
installTransport(transportMapBinder(), name, transportClass);
}
protected void addTransport(String name,
Class transportClass,
Class configClass,
Class> factoryClass) {
installTransport(transportMapBinder(), name, transportClass, configClass, factoryClass);
}
protected void addCodec(String name, Class codecClass) {
installCodec(codecMapBinder(), name, codecClass);
}
protected void addCodec(String name,
Class codecClass,
Class configClass,
Class> factoryClass) {
installCodec(codecMapBinder(), name, codecClass, configClass, factoryClass);
}
protected void addPasswordAlgorithm(String passwordAlgorithmName, Class passwordAlgorithmClass) {
passwordAlgorithmBinder().addBinding(passwordAlgorithmName).to(passwordAlgorithmClass);
}
protected Multibinder processorBinder() {
return Multibinder.newSetBinder(binder(), MessageProcessor.class);
}
protected Multibinder processorDescriptorBinder() {
return Multibinder.newSetBinder(binder(), MessageProcessor.Descriptor.class);
}
protected void addMessageProcessor(Class processorClass, Class descriptorClass) {
processorBinder().addBinding().to(processorClass);
processorDescriptorBinder().addBinding().to(descriptorClass);
}
protected void addWidgetStrategy(Class widgetStrategyClass, Class> factory) {
installWidgetStrategy(widgetStrategyBinder(), widgetStrategyClass, factory);
}
protected void addPermissions(Class permissionsClass) {
installPermissions(permissionsBinder(), permissionsClass);
}
protected void addAuditEventTypes(Class auditEventTypesClass) {
installAuditEventTypes(auditEventTypesBinder(), auditEventTypesClass);
}
protected void addAuditEventFormatter(AuditEventType auditEventType, Class auditEventFormatterClass) {
installAuditEventFormatter(auditEventFormatterMapBinder(), auditEventType, auditEventFormatterClass);
}
protected void addAlertCondition(String name,
Class alertConditionClass,
Class alertConditionFactoryClass) {
installAlertConditionWithCustomName(alertConditionBinder(), name, alertConditionClass, alertConditionFactoryClass);
}
protected void addMigration(Class migrationClass) {
migrationsBinder().addBinding().to(migrationClass);
}
protected void addEntityFacade(ModelType entityType, Class> entityFacadeClass) {
entityFacadeBinder().addBinding(entityType).to(entityFacadeClass);
}
protected void addConstraintChecker(Class constraintCheckerClass) {
constraintCheckerBinder().addBinding().to(constraintCheckerClass);
}
private MapBinder eventProcessorBinder() {
return MapBinder.newMapBinder(binder(), String.class, EventProcessor.Factory.class);
}
protected void addEventProcessor(String name,
Class processorClass,
Class factoryClass,
Class configClass,
Class parametersClass) {
install(new FactoryModuleBuilder().implement(EventProcessor.class, processorClass).build(factoryClass));
eventProcessorBinder().addBinding(name).to(factoryClass);
registerJacksonSubtype(configClass, name);
registerJacksonSubtype(parametersClass, name);
}
private MapBinder eventStorageHandlerBinder() {
return MapBinder.newMapBinder(binder(), String.class, EventStorageHandler.Factory.class);
}
protected void addEventStorageHandler(String name,
Class handlerClass,
Class factoryClass,
Class configClass) {
install(new FactoryModuleBuilder().implement(EventStorageHandler.class, handlerClass).build(factoryClass));
eventStorageHandlerBinder().addBinding(name).to(factoryClass);
registerJacksonSubtype(configClass, name);
}
private MapBinder eventFieldValueProviderBinder() {
return MapBinder.newMapBinder(binder(), String.class, FieldValueProvider.Factory.class);
}
protected void addEventFieldValueProvider(String name,
Class fieldValueProviderClass,
Class factoryClass,
Class configClass) {
install(new FactoryModuleBuilder().implement(FieldValueProvider.class, fieldValueProviderClass).build(factoryClass));
eventFieldValueProviderBinder().addBinding(name).to(factoryClass);
registerJacksonSubtype(configClass, name);
}
private MapBinder jobBinder() {
return MapBinder.newMapBinder(binder(), String.class, Job.Factory.class);
}
protected void addSchedulerJob(String name,
Class jobClass,
Class factoryClass,
Class configClass) {
addSchedulerJob(name, jobClass, factoryClass, configClass, null);
}
protected void addSchedulerJob(String name,
Class jobClass,
Class factoryClass,
Class configClass,
Class dataClass) {
install(new FactoryModuleBuilder().implement(Job.class, jobClass).build(factoryClass));
jobBinder().addBinding(name).to(factoryClass);
registerJacksonSubtype(configClass, name);
// Some jobs might not have a custom data class
if (dataClass != null) {
registerJacksonSubtype(dataClass, name);
}
}
protected void addJobSchedulerSchedule(String name, Class scheduleClass) {
registerJacksonSubtype(scheduleClass, name);
}
private MapBinder eventNotificationBinder() {
return MapBinder.newMapBinder(binder(), String.class, EventNotification.Factory.class);
}
protected void addNotificationType(String name,
Class notificationClass,
Class handlerClass,
Class factoryClass) {
install(new FactoryModuleBuilder().implement(EventNotification.class, handlerClass).build(factoryClass));
eventNotificationBinder().addBinding(name).to(factoryClass);
registerJacksonSubtype(notificationClass, name);
}
}