Search in sources :

Example 11 with Configuration

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

the class ConfigurationRequest method filter.

/**
     * Creates a new {@link org.graylog2.plugin.configuration.Configuration configuration object} containing only the
     * fields specified in this request object.
     * @param config original Configuration
     * @return filtered Configuration, not null but might be empty
     */
@Nonnull
public Configuration filter(Configuration config) {
    final Map<String, Object> values = Maps.newHashMap();
    for (final ConfigurationField field : fields.values()) {
        final String name = field.getName();
        final String type = field.getFieldType();
        switch(type) {
            case BooleanField.FIELD_TYPE:
                if (config.booleanIsSet(name)) {
                    values.put(name, config.getBoolean(name));
                }
                break;
            case NumberField.FIELD_TYPE:
                if (config.intIsSet(name)) {
                    values.put(name, config.getInt(name));
                }
                break;
            case TextField.FIELD_TYPE:
            case DropdownField.FIELD_TYPE:
                if (config.stringIsSet(name)) {
                    values.put(name, config.getString(name));
                }
                break;
            default:
                throw new IllegalStateException("Unknown field type " + type + ". This is a bug.");
        }
    }
    return new Configuration(values);
}
Also used : ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) Nonnull(javax.annotation.Nonnull)

Example 12 with Configuration

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

the class UdpTransportTest method receiveBufferSizeIsNotLimited.

@Test
public void receiveBufferSizeIsNotLimited() throws Exception {
    final int recvBufferSize = Ints.saturatedCast(Size.megabytes(1L).toBytes());
    ImmutableMap<String, Object> source = ImmutableMap.<String, Object>of(NettyTransport.CK_BIND_ADDRESS, BIND_ADDRESS, NettyTransport.CK_PORT, PORT, NettyTransport.CK_RECV_BUFFER_SIZE, recvBufferSize);
    Configuration config = new Configuration(source);
    UdpTransport udpTransport = new UdpTransport(config, throughputCounter, new LocalMetricRegistry());
    assertThat(udpTransport.getBootstrap().getOption("receiveBufferSize")).isEqualTo(recvBufferSize);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Test(org.junit.Test)

Example 13 with Configuration

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

the class UdpTransportTest method setUp.

@Before
public void setUp() throws Exception {
    throughputCounter = new ThroughputCounter(new HashedWheelTimer());
    localMetricRegistry = new LocalMetricRegistry();
    udpTransport = new UdpTransport(CONFIGURATION, throughputCounter, localMetricRegistry);
}
Also used : ThroughputCounter(org.graylog2.plugin.inputs.util.ThroughputCounter) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Before(org.junit.Before)

Example 14 with Configuration

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

the class MessageOutputFactoryTest method testNonExistentOutputType.

@Test(expected = IllegalArgumentException.class)
public void testNonExistentOutputType() throws MessageOutputConfigurationException {
    final String outputType = "non.existent";
    final Output output = mock(Output.class);
    when(output.getType()).thenReturn(outputType);
    final Stream stream = mock(Stream.class);
    final Configuration configuration = mock(Configuration.class);
    messageOutputFactory.fromStreamOutput(output, stream, configuration);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 15 with Configuration

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

the class StreamServiceImpl method updateCallbackConfiguration.

// I tried to be sorry, really. https://www.youtube.com/watch?v=3KVyRqloGmk
private void updateCallbackConfiguration(String action, String type, String entity, List<AlarmCallbackConfiguration> streamCallbacks) {
    final AtomicBoolean ran = new AtomicBoolean(false);
    streamCallbacks.stream().filter(callback -> callback.getType().equals(EmailAlarmCallback.class.getCanonicalName())).forEach(callback -> {
        ran.set(true);
        final Map<String, Object> configuration = callback.getConfiguration();
        String key;
        if ("users".equals(type)) {
            key = EmailAlarmCallback.CK_USER_RECEIVERS;
        } else {
            key = EmailAlarmCallback.CK_EMAIL_RECEIVERS;
        }
        @SuppressWarnings("unchecked") final List<String> recipients = (List<String>) configuration.get(key);
        if ("add".equals(action)) {
            if (!recipients.contains(entity)) {
                recipients.add(entity);
            }
        } else {
            if (recipients.contains(entity)) {
                recipients.remove(entity);
            }
        }
        configuration.put(key, recipients);
        final AlarmCallbackConfiguration updatedConfig = ((AlarmCallbackConfigurationImpl) callback).toBuilder().setConfiguration(configuration).build();
        try {
            alarmCallbackConfigurationService.save(updatedConfig);
        } catch (ValidationException e) {
            throw new BadRequestException("Unable to save alarm callback configuration", e);
        }
    });
    if (!ran.get()) {
        throw new BadRequestException("Unable to " + action + " receiver: Stream has no email alarm callback.");
    }
}
Also used : QueryBuilder(com.mongodb.QueryBuilder) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) EmailAlarmCallback(org.graylog2.alarmcallbacks.EmailAlarmCallback) HashMap(java.util.HashMap) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlertService(org.graylog2.alerts.AlertService) StreamRule(org.graylog2.plugin.streams.StreamRule) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) DBObject(com.mongodb.DBObject) Map(java.util.Map) MongoIndexSet(org.graylog2.indexer.MongoIndexSet) EmbeddedPersistable(org.graylog2.plugin.database.EmbeddedPersistable) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) Alert(org.graylog2.alerts.Alert) PersistedServiceImpl(org.graylog2.database.PersistedServiceImpl) NotFoundException(org.graylog2.database.NotFoundException) Nullable(javax.annotation.Nullable) Notification(org.graylog2.notifications.Notification) Logger(org.slf4j.Logger) NotificationService(org.graylog2.notifications.NotificationService) BasicDBObject(com.mongodb.BasicDBObject) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) AlarmCallbackConfigurationImpl(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationImpl) AlarmCallbackConfigurationService(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationService) CreateStreamRequest(org.graylog2.rest.resources.streams.requests.CreateStreamRequest) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Output(org.graylog2.plugin.streams.Output) Stream(org.graylog2.plugin.streams.Stream) ValidationException(org.graylog2.plugin.database.ValidationException) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) ObjectId(org.bson.types.ObjectId) Optional(java.util.Optional) MongoConnection(org.graylog2.database.MongoConnection) Collections(java.util.Collections) ValidationException(org.graylog2.plugin.database.ValidationException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BadRequestException(javax.ws.rs.BadRequestException) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EmailAlarmCallback(org.graylog2.alarmcallbacks.EmailAlarmCallback) AlarmCallbackConfigurationImpl(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationImpl) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)

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