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