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);
}
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);
}
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);
}
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);
}
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.");
}
}
Aggregations