Search in sources :

Example 6 with Plugin

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

the class PermissionsTest method testPluginPermissions.

@Test
public void testPluginPermissions() throws Exception {
    final ImmutableSet<Permission> pluginPermissions = ImmutableSet.of(Permission.create("foo:bar", "bar"), Permission.create("foo:baz", "baz"), Permission.create("hello:world", "hello"));
    final PermissionsPluginPermissions plugin = new PermissionsPluginPermissions(pluginPermissions);
    final Permissions permissions = new Permissions(ImmutableSet.of(restPermissions, plugin));
    assertThat(permissions.allPermissionsMap().get("foo")).containsOnly("bar", "baz");
    assertThat(permissions.allPermissionsMap().get("hello")).containsOnly("world");
}
Also used : Permission(org.graylog2.plugin.security.Permission) PluginPermissions(org.graylog2.plugin.security.PluginPermissions) Test(org.junit.Test)

Example 7 with Plugin

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

the class CmdLineTool method installPluginConfigAndBindings.

private PluginBindings installPluginConfigAndBindings(String pluginPath, ChainingClassLoader classLoader) {
    final Set<Plugin> plugins = loadPlugins(pluginPath, classLoader);
    final PluginBindings pluginBindings = new PluginBindings(plugins);
    for (final Plugin plugin : plugins) {
        for (final PluginModule pluginModule : plugin.modules()) {
            for (final PluginConfigBean configBean : pluginModule.getConfigBeans()) {
                jadConfig.addConfigurationBean(configBean);
            }
        }
    }
    return pluginBindings;
}
Also used : PluginConfigBean(org.graylog2.plugin.PluginConfigBean) PluginBindings(org.graylog2.shared.bindings.PluginBindings) PluginModule(org.graylog2.plugin.PluginModule) Plugin(org.graylog2.plugin.Plugin)

Example 8 with Plugin

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

the class CmdLineTool method loadPlugins.

protected Set<Plugin> loadPlugins(Path pluginPath, ChainingClassLoader chainingClassLoader) {
    final Set<Plugin> plugins = new HashSet<>();
    final PluginLoader pluginLoader = new PluginLoader(pluginPath.toFile(), chainingClassLoader, coreConfigInjector);
    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) PluginLoader(org.graylog2.shared.plugins.PluginLoader) Plugin(org.graylog2.plugin.Plugin) HashSet(java.util.HashSet)

Example 9 with Plugin

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

the class CmdLineTool method run.

@Override
public void run() {
    final Level logLevel = setupLogger();
    if (isDumpDefaultConfig()) {
        dumpDefaultConfigAndExit();
    }
    // This is holding all our metrics.
    MetricRegistry metricRegistry = MetricRegistryFactory.create();
    featureFlags = getFeatureFlags(metricRegistry);
    installConfigRepositories();
    installCommandConfig();
    beforeStart();
    beforeStart(parseAndGetTLSConfiguration(), parseAndGetPathConfiguration(configFile));
    processConfiguration(jadConfig);
    coreConfigInjector = setupCoreConfigInjector();
    final Set<Plugin> plugins = loadPlugins(getPluginPath(configFile), chainingClassLoader);
    installPluginConfig(plugins);
    processConfiguration(jadConfig);
    if (isDumpConfig()) {
        dumpCurrentConfigAndExit();
    }
    if (!validateConfiguration()) {
        LOG.error("Validating configuration file failed - exiting.");
        System.exit(1);
    }
    final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));
    beforeInjectorCreation(plugins);
    injector = setupInjector(new NamedConfigParametersModule(jadConfig.getConfigurationBeans()), new PluginBindings(plugins), binder -> binder.bind(MetricRegistry.class).toInstance(metricRegistry));
    if (injector == null) {
        LOG.error("Injector could not be created, exiting! (Please include the previous error messages in bug " + "reports.)");
        System.exit(1);
    }
    addInstrumentedAppender(metricRegistry, logLevel);
    // Report metrics via JMX.
    final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).build();
    reporter.start();
    startCommand();
}
Also used : NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) Option(com.github.rvesse.airline.annotations.Option) Module(com.google.inject.Module) Plugin(org.graylog2.plugin.Plugin) Arrays(java.util.Arrays) ParameterException(com.github.joschi.jadconfig.ParameterException) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException) FeatureFlagsFactory(org.graylog2.featureflag.FeatureFlagsFactory) GuiceInjectorHolder(org.graylog2.shared.bindings.GuiceInjectorHolder) RepositoryException(com.github.joschi.jadconfig.RepositoryException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Level(org.apache.logging.log4j.Level) Security(java.security.Security) InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) Message(com.google.inject.spi.Message) PluginLoaderConfig(org.graylog2.plugin.PluginLoaderConfig) Map(java.util.Map) UnsupportedSearchException(org.graylog2.storage.UnsupportedSearchException) Version(org.graylog2.plugin.Version) PropertiesRepository(com.github.joschi.jadconfig.repositories.PropertiesRepository) Command(com.github.rvesse.airline.annotations.Command) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) Path(java.nio.file.Path) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) Slf4JLoggerFactory(io.netty.util.internal.logging.Slf4JLoggerFactory) ImmutableSet(com.google.common.collect.ImmutableSet) JodaTimeConverterFactory(com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory) Collection(java.util.Collection) Set(java.util.Set) ServerStatus(org.graylog2.plugin.ServerStatus) SearchVersion(org.graylog2.storage.SearchVersion) ValidationException(com.github.joschi.jadconfig.ValidationException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Stage(com.google.inject.Stage) List(java.util.List) Stream(java.util.stream.Stream) Configuration(org.graylog2.Configuration) DocsHelper(org.graylog2.plugin.DocsHelper) PluginBindings(org.graylog2.shared.bindings.PluginBindings) PathConfiguration(org.graylog2.configuration.PathConfiguration) PluginMetaData(org.graylog2.plugin.PluginMetaData) ElasticsearchProbeException(org.graylog2.storage.versionprobe.ElasticsearchProbeException) UI(org.graylog2.shared.UI) AccessDeniedException(java.nio.file.AccessDeniedException) GuavaConverterFactory(com.github.joschi.jadconfig.guava.GuavaConverterFactory) Joiner(com.google.common.base.Joiner) EnvironmentRepository(com.github.joschi.jadconfig.repositories.EnvironmentRepository) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) Strings(joptsimple.internal.Strings) HashSet(java.util.HashSet) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) SystemPropertiesRepository(com.github.joschi.jadconfig.repositories.SystemPropertiesRepository) JadConfig(com.github.joschi.jadconfig.JadConfig) ManagementFactory(java.lang.management.ManagementFactory) NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) MigrateCmd(org.graylog2.bootstrap.commands.MigrateCmd) FeatureFlags(org.graylog2.featureflag.FeatureFlags) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) Names(com.google.inject.name.Names) PluginLoader(org.graylog2.shared.plugins.PluginLoader) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) Repository(com.github.joschi.jadconfig.Repository) Guice(com.google.inject.Guice) MetricRegistryFactory(org.graylog2.shared.metrics.MetricRegistryFactory) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) PluginBindings(org.graylog2.shared.bindings.PluginBindings) MetricRegistry(com.codahale.metrics.MetricRegistry) Level(org.apache.logging.log4j.Level) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Plugin(org.graylog2.plugin.Plugin)

Example 10 with Plugin

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

the class LookupTableService method createCache.

private LookupCache createCache(CacheDto dto) {
    try {
        final LookupCache.Factory<? extends LookupCache> factory = cacheFactories.get(dto.config().type());
        if (factory == null) {
            LOG.warn("Unable to load cache {} of type {}, missing a factory. Is a required plugin missing?", dto.name(), dto.config().type());
            // TODO system notification
            return null;
        }
        final LookupCache cache = factory.create(dto.id(), dto.name(), dto.config());
        cache.addListener(new LoggingServiceListener("Cache", String.format(Locale.ENGLISH, "%s/%s [@%s]", dto.name(), dto.id(), objectId(cache)), LOG), scheduler);
        return cache;
    } catch (Exception e) {
        LOG.error("Couldn't create cache <{}/{}>", dto.name(), dto.id(), e);
        return null;
    }
}
Also used : LookupCache(org.graylog2.plugin.lookup.LookupCache) LoggingServiceListener(org.graylog2.utilities.LoggingServiceListener)

Aggregations

Plugin (org.graylog2.plugin.Plugin)6 PluginMetaData (org.graylog2.plugin.PluginMetaData)4 HashSet (java.util.HashSet)3 PluginLoader (org.graylog2.shared.plugins.PluginLoader)3 Injector (com.google.inject.Injector)2 ApiOperation (io.swagger.annotations.ApiOperation)2 PluginBindings (org.graylog2.shared.bindings.PluginBindings)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timed (com.codahale.metrics.annotation.Timed)1 JmxReporter (com.codahale.metrics.jmx.JmxReporter)1 InstrumentedAppender (com.codahale.metrics.log4j2.InstrumentedAppender)1 JadConfig (com.github.joschi.jadconfig.JadConfig)1 ParameterException (com.github.joschi.jadconfig.ParameterException)1 Repository (com.github.joschi.jadconfig.Repository)1 RepositoryException (com.github.joschi.jadconfig.RepositoryException)1 ValidationException (com.github.joschi.jadconfig.ValidationException)1 GuavaConverterFactory (com.github.joschi.jadconfig.guava.GuavaConverterFactory)1 NamedConfigParametersModule (com.github.joschi.jadconfig.guice.NamedConfigParametersModule)1 JodaTimeConverterFactory (com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory)1 EnvironmentRepository (com.github.joschi.jadconfig.repositories.EnvironmentRepository)1