Search in sources :

Example 71 with Configuration

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

the class UserServiceImplTest method testGetRoleNames.

@Test
public void testGetRoleNames() throws Exception {
    final UserImplFactory factory = new UserImplFactory(new Configuration());
    final UserImpl user = factory.create(new HashMap<>());
    final Role role = createRole("Foo");
    final ImmutableMap<String, Role> map = ImmutableMap.<String, Role>builder().put(role.getId(), role).build();
    when(roleService.loadAllIdMap()).thenReturn(map);
    assertThat(userService.getRoleNames(user)).isEmpty();
    user.setRoleIds(Sets.newHashSet(role.getId()));
    assertThat(userService.getRoleNames(user)).containsOnly("Foo");
    when(roleService.loadAllIdMap()).thenReturn(new HashMap<>());
    assertThat(userService.getRoleNames(user)).isEmpty();
}
Also used : Role(org.graylog2.shared.users.Role) Configuration(org.graylog2.Configuration) Test(org.junit.Test)

Example 72 with Configuration

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

the class ConfigurationMapConverterTest method convertValuesThrowsIllegalArgumentExceptionOnEmptyFieldDescription.

@Test
public void convertValuesThrowsIllegalArgumentExceptionOnEmptyFieldDescription() throws Exception {
    thrown.expect(ValidationException.class);
    thrown.expectMessage("Unknown configuration field description for field \"string\"");
    final ConfigurationRequest cr = new ConfigurationRequest();
    final Map<String, Object> data = new HashMap<>();
    data.put("string", "foo");
    ConfigurationMapConverter.convertValues(data, cr);
}
Also used : HashMap(java.util.HashMap) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) Test(org.junit.Test)

Example 73 with Configuration

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

the class IndexRotationThread method checkForRotation.

protected void checkForRotation(IndexSet indexSet) {
    final IndexSetConfig config = indexSet.getConfig();
    final Provider<RotationStrategy> rotationStrategyProvider = rotationStrategyMap.get(config.rotationStrategyClass());
    if (rotationStrategyProvider == null) {
        LOG.warn("Rotation strategy \"{}\" not found, not running index rotation!", config.rotationStrategyClass());
        rotationProblemNotification("Index Rotation Problem!", "Index rotation strategy " + config.rotationStrategyClass() + " not found! Please fix your index rotation configuration!");
        return;
    }
    final RotationStrategy rotationStrategy = rotationStrategyProvider.get();
    if (rotationStrategy == null) {
        LOG.warn("No rotation strategy found, not running index rotation!");
        return;
    }
    rotationStrategy.rotate(indexSet);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy)

Example 74 with Configuration

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

the class GelfOutput method buildTransport.

protected static GelfTransport buildTransport(final Configuration configuration) throws MessageOutputConfigurationException {
    final String protocol = configuration.getString(CK_PROTOCOL);
    final String hostname = configuration.getString(CK_HOSTNAME);
    final int port = configuration.getInt(CK_PORT);
    final int connectTimeout = configuration.getInt(CK_CONNECT_TIMEOUT, 1000);
    final int reconnectDelay = configuration.getInt(CK_RECONNECT_DELAY, 500);
    final boolean tcpKeepAlive = configuration.getBoolean(CK_TCP_KEEP_ALIVE, false);
    final boolean tcpNoDelay = configuration.getBoolean(CK_TCP_NO_DELAY, false);
    final boolean tlsVerificationEnabled = configuration.getBoolean(CK_TLS_VERIFICATION_ENABLED, false);
    final String tlsTrustCertChain = configuration.getString(CK_TLS_TRUST_CERT_CHAIN);
    final int queueSize = configuration.getInt(CK_QUEUE_SIZE, 512);
    final int maxInflightSends = configuration.getInt(CK_MAX_INFLIGHT_SENDS, 512);
    if (isNullOrEmpty(protocol) || isNullOrEmpty(hostname) || !configuration.intIsSet(CK_PORT)) {
        throw new MessageOutputConfigurationException("Protocol and/or hostname missing!");
    }
    final GelfTransports transport;
    final boolean tlsEnabled;
    switch(protocol.toUpperCase(Locale.ENGLISH)) {
        case "UDP":
            transport = GelfTransports.UDP;
            tlsEnabled = false;
            break;
        case "TCP":
            transport = GelfTransports.TCP;
            tlsEnabled = false;
            break;
        case "TCP+TLS":
            transport = GelfTransports.TCP;
            tlsEnabled = true;
            break;
        default:
            throw new MessageOutputConfigurationException("Unknown protocol " + protocol);
    }
    final File tlsTrustCertChainFile;
    if (tlsEnabled && !isNullOrEmpty(tlsTrustCertChain)) {
        tlsTrustCertChainFile = new File(tlsTrustCertChain);
        if (!tlsTrustCertChainFile.isFile() && !tlsTrustCertChainFile.canRead()) {
            throw new MessageOutputConfigurationException("TLS trust certificate chain file cannot be read!");
        }
    } else {
        tlsTrustCertChainFile = null;
    }
    final GelfConfiguration gelfConfiguration = new GelfConfiguration(hostname, port).transport(transport).connectTimeout(connectTimeout).reconnectDelay(reconnectDelay).tcpKeepAlive(tcpKeepAlive).tcpNoDelay(tcpNoDelay).queueSize(queueSize).maxInflightSends(maxInflightSends);
    if (tlsEnabled) {
        gelfConfiguration.enableTls();
        if (tlsVerificationEnabled) {
            gelfConfiguration.enableTlsCertVerification();
        } else {
            gelfConfiguration.disableTlsCertVerification();
        }
        if (tlsTrustCertChainFile != null) {
            gelfConfiguration.tlsTrustCertChainFile(tlsTrustCertChainFile);
        }
    }
    LOG.debug("Initializing GELF sender and connecting to {}://{}:{}", protocol, hostname, port);
    try {
        return GelfTransports.create(gelfConfiguration);
    } catch (Exception e) {
        final String error = "Error initializing " + GelfOutput.class;
        LOG.error(error, e);
        throw new MessageOutputConfigurationException(error);
    }
}
Also used : GelfTransports(org.graylog2.gelfclient.GelfTransports) GelfConfiguration(org.graylog2.gelfclient.GelfConfiguration) MessageOutputConfigurationException(org.graylog2.plugin.outputs.MessageOutputConfigurationException) File(java.io.File) MessageOutputConfigurationException(org.graylog2.plugin.outputs.MessageOutputConfigurationException)

Example 75 with Configuration

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

the class InputServiceImpl method getMessageInput.

@Override
public MessageInput getMessageInput(Input io) throws NoSuchInputTypeException {
    final Configuration configuration = new Configuration(io.getConfiguration());
    final MessageInput input = messageInputFactory.create(io.getType(), configuration);
    // Add all standard fields.
    input.setTitle(io.getTitle());
    input.setNodeId(io.getNodeId());
    input.setCreatorUserId(io.getCreatorUserId());
    input.setPersistId(io.getId());
    input.setCreatedAt(io.getCreatedAt());
    input.setContentPack(io.getContentPack());
    if (io.isGlobal()) {
        input.setGlobal(true);
    }
    // Add static fields.
    input.addStaticFields(io.getStaticFields());
    return input;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput)

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