Search in sources :

Example 1 with PluginMetaData

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

the class CmdLineTool method loadPlugins.

protected Set<Plugin> loadPlugins(String pluginPath, ChainingClassLoader chainingClassLoader) {
    final File pluginDir = new File(pluginPath);
    final Set<Plugin> plugins = new HashSet<>();
    final PluginLoader pluginLoader = new PluginLoader(pluginDir, chainingClassLoader);
    for (Plugin plugin : pluginLoader.loadPlugins()) {
        final PluginMetaData metadata = plugin.metadata();
        if (capabilities().containsAll(metadata.getRequiredCapabilities())) {
            if (version.sameOrHigher(metadata.getRequiredVersion())) {
                LOG.info("Loaded plugin: {}", plugin);
                plugins.add(plugin);
            } else {
                LOG.error("Plugin \"" + metadata.getName() + "\" requires version " + metadata.getRequiredVersion() + " - not loading!");
            }
        } else {
            LOG.debug("Skipping plugin \"{}\" because some capabilities are missing ({}).", metadata.getName(), Sets.difference(plugin.metadata().getRequiredCapabilities(), capabilities()));
        }
    }
    return plugins;
}
Also used : PluginMetaData(org.graylog2.plugin.PluginMetaData) File(java.io.File) PluginLoader(org.graylog2.shared.plugins.PluginLoader) HashSet(java.util.HashSet) Plugin(org.graylog2.plugin.Plugin)

Example 2 with PluginMetaData

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

the class PluginBindings method configure.

@Override
protected void configure() {
    final Multibinder<Plugin> pluginbinder = Multibinder.newSetBinder(binder(), Plugin.class);
    final Multibinder<PluginMetaData> pluginMetaDataBinder = Multibinder.newSetBinder(binder(), PluginMetaData.class);
    // Make sure there is a binding for the plugin rest resource classes to avoid binding errors when running
    // without plugins.
    MapBinder.newMapBinder(binder(), new TypeLiteral<String>() {
    }, new TypeLiteral<Class<? extends PluginRestResource>>() {
    }).permitDuplicates();
    // Make sure there is a binding for the PluginUISettingsProvider classes to avoid binding errors when running
    // without plugins
    MapBinder.newMapBinder(binder(), String.class, PluginUISettingsProvider.class).permitDuplicates();
    for (final Plugin plugin : plugins) {
        pluginbinder.addBinding().toInstance(plugin);
        for (final PluginModule pluginModule : plugin.modules()) {
            binder().install(pluginModule);
        }
        pluginMetaDataBinder.addBinding().toInstance(plugin.metadata());
    }
}
Also used : TypeLiteral(com.google.inject.TypeLiteral) PluginUISettingsProvider(org.graylog2.web.PluginUISettingsProvider) PluginMetaData(org.graylog2.plugin.PluginMetaData) PluginModule(org.graylog2.plugin.PluginModule) Plugin(org.graylog2.plugin.Plugin)

Example 3 with PluginMetaData

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

the class PluginVersionConstraint method of.

public static PluginVersionConstraint of(PluginMetaData pluginMetaData) {
    final Version version = pluginMetaData.getVersion();
    final String versionString = version.toString().replace("-SNAPSHOT", "");
    final Requirement requirement = Requirement.buildNPM(">=" + versionString);
    return builder().pluginId(pluginMetaData.getUniqueId()).version(requirement).build();
}
Also used : Requirement(com.vdurmont.semver4j.Requirement) Version(org.graylog2.plugin.Version)

Example 4 with PluginMetaData

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

the class LookupCacheFacadeTest method setUp.

@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() throws Exception {
    final ClusterEventBus clusterEventBus = new ClusterEventBus("cluster-event-bus", Executors.newSingleThreadExecutor());
    cacheService = new DBCacheService(mongodb.mongoConnection(), new MongoJackObjectMapperProvider(objectMapper), clusterEventBus);
    pluginMetaData = new HashSet<>();
    facade = new LookupCacheFacade(objectMapper, cacheService, pluginMetaData);
}
Also used : MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ClusterEventBus(org.graylog2.events.ClusterEventBus) DBCacheService(org.graylog2.lookup.db.DBCacheService) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 5 with PluginMetaData

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

the class InputFacadeTest method setUp.

@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() throws Exception {
    final MetricRegistry metricRegistry = new MetricRegistry();
    final ClusterEventBus clusterEventBus = new ClusterEventBus("cluster-event-bus", Executors.newSingleThreadExecutor());
    final GrokPatternService grokPatternService = new InMemoryGrokPatternService(clusterEventBus);
    grokPatternService.save(GrokPattern.create("GREEDY", ".*"));
    final EventBus clusterBus = new EventBus();
    final GrokPatternRegistry grokPatternRegistry = new GrokPatternRegistry(clusterBus, grokPatternService, Executors.newScheduledThreadPool(1));
    final ExtractorFactory extractorFactory = new ExtractorFactory(metricRegistry, grokPatternRegistry, lookupTableService);
    final ConverterFactory converterFactory = new ConverterFactory(lookupTableService);
    inputService = new InputServiceImpl(mongodb.mongoConnection(), extractorFactory, converterFactory, messageInputFactory, clusterEventBus);
    final InputRegistry inputRegistry = new InputRegistry();
    Set<PluginMetaData> pluginMetaData = new HashSet<>();
    Map<String, MessageInput.Factory<? extends MessageInput>> inputFactories = new HashMap<>();
    final FakeHttpMessageInput.Factory fakeHttpMessageInputFactory = mock(FakeHttpMessageInput.Factory.class);
    final FakeHttpMessageInput.Descriptor fakeHttpMessageInputDescriptor = mock(FakeHttpMessageInput.Descriptor.class);
    when(fakeHttpMessageInputFactory.getDescriptor()).thenReturn(fakeHttpMessageInputDescriptor);
    final RawUDPInput.Factory rawUDPInputFactory = mock(RawUDPInput.Factory.class);
    final RawUDPInput.Descriptor rawUDPInputDescriptor = mock(RawUDPInput.Descriptor.class);
    when(rawUDPInputFactory.getDescriptor()).thenReturn(rawUDPInputDescriptor);
    inputFactories.put("org.graylog2.inputs.random.FakeHttpMessageInput", fakeHttpMessageInputFactory);
    inputFactories.put("org.graylog2.inputs.raw.udp.RawUDPInput", rawUDPInputFactory);
    facade = new InputFacade(objectMapper, inputService, inputRegistry, dbLookupTableService, grokPatternService, messageInputFactory, extractorFactory, converterFactory, serverStatus, pluginMetaData, inputFactories);
}
Also used : HashMap(java.util.HashMap) InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) ExtractorFactory(org.graylog2.inputs.extractors.ExtractorFactory) PluginMetaData(org.graylog2.plugin.PluginMetaData) MessageInputFactory(org.graylog2.shared.inputs.MessageInputFactory) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) ExtractorFactory(org.graylog2.inputs.extractors.ExtractorFactory) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) ClusterEventBus(org.graylog2.events.ClusterEventBus) EventBus(com.google.common.eventbus.EventBus) InputRegistry(org.graylog2.shared.inputs.InputRegistry) InputServiceImpl(org.graylog2.inputs.InputServiceImpl) GrokPatternService(org.graylog2.grok.GrokPatternService) InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) GrokPatternRegistry(org.graylog2.grok.GrokPatternRegistry) HashSet(java.util.HashSet) MetricRegistry(com.codahale.metrics.MetricRegistry) ClusterEventBus(org.graylog2.events.ClusterEventBus) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Aggregations

Before (org.junit.Before)6 PluginMetaData (org.graylog2.plugin.PluginMetaData)5 HashSet (java.util.HashSet)4 SuppressForbidden (org.graylog2.shared.SuppressForbidden)4 MongoJackObjectMapperProvider (org.graylog2.bindings.providers.MongoJackObjectMapperProvider)3 ClusterEventBus (org.graylog2.events.ClusterEventBus)3 Plugin (org.graylog2.plugin.Plugin)3 HashMap (java.util.HashMap)2 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)2 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)2 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)2 Test (org.junit.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EventBus (com.google.common.eventbus.EventBus)1 TypeLiteral (com.google.inject.TypeLiteral)1 Requirement (com.vdurmont.semver4j.Requirement)1 File (java.io.File)1 TemplateFieldValueProvider (org.graylog.events.fields.providers.TemplateFieldValueProvider)1 DBEventDefinitionService (org.graylog.events.processor.DBEventDefinitionService)1