Search in sources :

Example 76 with Configuration

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

the class MessageInputFactory method create.

public MessageInput create(InputCreateRequest lr, String user, String nodeId) throws NoSuchInputTypeException {
    final MessageInput input = create(lr.type(), new Configuration(lr.configuration()));
    input.setTitle(lr.title());
    input.setGlobal(lr.global());
    input.setCreatorUserId(user);
    input.setCreatedAt(Tools.nowUTC());
    if (!lr.global())
        input.setNodeId(nodeId);
    return input;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 77 with Configuration

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

the class BlockingBatchedESOutputTest method setUp.

@Before
public void setUp() throws Exception {
    this.metricRegistry = new MetricRegistry();
    this.journal = new NoopJournal();
    this.config = new Configuration() {

        @Override
        public int getOutputBatchSize() {
            return 3;
        }
    };
}
Also used : Configuration(org.graylog2.Configuration) NoopJournal(org.graylog2.shared.journal.NoopJournal) MetricRegistry(com.codahale.metrics.MetricRegistry) Before(org.junit.Before)

Example 78 with Configuration

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

the class UdpTransportTest method launchTransportForBootStrapTest.

private UdpTransport launchTransportForBootStrapTest(final ChannelHandler channelHandler) throws MisfireException {
    final UdpTransport transport = new UdpTransport(CONFIGURATION, throughputCounter, new LocalMetricRegistry()) {

        @Override
        protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getBaseChannelHandlers(MessageInput input) {
            final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
            handlers.put("counter", Callables.returning(channelHandler));
            handlers.putAll(super.getFinalChannelHandlers(input));
            return handlers;
        }
    };
    final MessageInput messageInput = mock(MessageInput.class);
    when(messageInput.getId()).thenReturn("TEST");
    when(messageInput.getName()).thenReturn("TEST");
    transport.launch(messageInput);
    return transport;
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(org.jboss.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) LinkedHashMap(java.util.LinkedHashMap)

Example 79 with Configuration

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

the class CmdLineTool method run.

@Override
public void run() {
    final Level logLevel = setupLogger();
    final PluginBindings pluginBindings = installPluginConfigAndBindings(getPluginPath(configFile), chainingClassLoader);
    if (isDumpDefaultConfig()) {
        dumpDefaultConfigAndExit();
    }
    final NamedConfigParametersModule configModule = readConfiguration(configFile);
    if (isDumpConfig()) {
        dumpCurrentConfigAndExit();
    }
    if (!validateConfiguration()) {
        LOG.error("Validating configuration file failed - exiting.");
        System.exit(1);
    }
    beforeStart();
    final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));
    injector = setupInjector(configModule, pluginBindings, binder -> binder.bind(ChainingClassLoader.class).toInstance(chainingClassLoader));
    if (injector == null) {
        LOG.error("Injector could not be created, exiting! (Please include the previous error messages in bug reports.)");
        System.exit(1);
    }
    // This is holding all our metrics.
    final MetricRegistry metrics = injector.getInstance(MetricRegistry.class);
    addInstrumentedAppender(metrics, logLevel);
    // Report metrics via JMX.
    final JmxReporter reporter = JmxReporter.forRegistry(metrics).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) 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) InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory) Message(com.google.inject.spi.Message) PluginLoaderConfig(org.graylog2.plugin.PluginLoaderConfig) Map(java.util.Map) InternalLoggerFactory(org.jboss.netty.logging.InternalLoggerFactory) Version(org.graylog2.plugin.Version) JmxReporter(com.codahale.metrics.JmxReporter) PropertiesRepository(com.github.joschi.jadconfig.repositories.PropertiesRepository) Command(com.github.rvesse.airline.annotations.Command) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) PluginModule(org.graylog2.plugin.PluginModule) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) JodaTimeConverterFactory(com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory) Collection(java.util.Collection) Set(java.util.Set) ServerStatus(org.graylog2.plugin.ServerStatus) ValidationException(com.github.joschi.jadconfig.ValidationException) Sets(com.google.common.collect.Sets) List(java.util.List) PluginBindings(org.graylog2.shared.bindings.PluginBindings) PluginMetaData(org.graylog2.plugin.PluginMetaData) 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) HashSet(java.util.HashSet) 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) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) PluginConfigBean(org.graylog2.plugin.PluginConfigBean) Names(com.google.inject.name.Names) PluginLoader(org.graylog2.shared.plugins.PluginLoader) File(java.io.File) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) Repository(com.github.joschi.jadconfig.Repository) BaseConfiguration(org.graylog2.plugin.BaseConfiguration) 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.JmxReporter) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader)

Example 80 with Configuration

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

the class Server method startNodeRegistration.

@Override
protected void startNodeRegistration(Injector injector) {
    // Register this node.
    final NodeService nodeService = injector.getInstance(NodeService.class);
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    final ActivityWriter activityWriter = injector.getInstance(ActivityWriter.class);
    nodeService.registerServer(serverStatus.getNodeId().toString(), configuration.isMaster(), configuration.getRestTransportUri(), Tools.getLocalCanonicalHostname());
    serverStatus.setLocalMode(isLocal());
    if (configuration.isMaster() && !nodeService.isOnlyMaster(serverStatus.getNodeId())) {
        LOG.warn("Detected another master in the cluster. Retrying in {} seconds to make sure it is not " + "an old stale instance.", TimeUnit.MILLISECONDS.toSeconds(configuration.getStaleMasterTimeout()));
        try {
            Thread.sleep(configuration.getStaleMasterTimeout());
        } catch (InterruptedException e) {
        /* nope */
        }
        if (!nodeService.isOnlyMaster(serverStatus.getNodeId())) {
            // All devils here.
            String what = "Detected other master node in the cluster! Starting as non-master! " + "This is a mis-configuration you should fix.";
            LOG.warn(what);
            activityWriter.write(new Activity(what, Server.class));
            // Write a notification.
            final NotificationService notificationService = injector.getInstance(NotificationService.class);
            Notification notification = notificationService.buildNow().addType(Notification.Type.MULTI_MASTER).addSeverity(Notification.Severity.URGENT);
            notificationService.publishIfFirst(notification);
            configuration.setIsMaster(false);
        } else {
            LOG.warn("Stale master has gone. Starting as master.");
        }
    }
}
Also used : NodeService(org.graylog2.cluster.NodeService) ServerStatus(org.graylog2.plugin.ServerStatus) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) Activity(org.graylog2.shared.system.activities.Activity) NotificationService(org.graylog2.notifications.NotificationService) Notification(org.graylog2.notifications.Notification)

Aggregations

Test (org.junit.Test)34 Configuration (org.graylog2.plugin.configuration.Configuration)29 ApiOperation (io.swagger.annotations.ApiOperation)24 Timed (com.codahale.metrics.annotation.Timed)23 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)17 Consumes (javax.ws.rs.Consumes)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Stream (org.graylog2.plugin.streams.Stream)13 ApiResponses (io.swagger.annotations.ApiResponses)12 PUT (javax.ws.rs.PUT)11 ValidationException (org.graylog2.plugin.database.ValidationException)11 DateTime (org.joda.time.DateTime)11 Produces (javax.ws.rs.Produces)10 Configuration (org.graylog2.Configuration)10 POST (javax.ws.rs.POST)9 EmailConfiguration (org.graylog2.configuration.EmailConfiguration)9 URI (java.net.URI)8