use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class CmdLineTool method setupCoreConfigInjector.
/**
* Set up a separate injector, containing only the core configuration bindings. It can be used to look up
* configuration values in modules at binding time.
*/
protected Injector setupCoreConfigInjector() {
final NamedConfigParametersModule configModule = new NamedConfigParametersModule(jadConfig.getConfigurationBeans());
Injector coreConfigInjector = null;
try {
coreConfigInjector = Guice.createInjector(Stage.PRODUCTION, ImmutableList.of(configModule, (Module) Binder::requireExplicitBindings, this::featureFlagsBinding));
} catch (CreationException e) {
annotateInjectorCreationException(e);
} catch (Exception e) {
LOG.error("Injector creation failed!", e);
}
if (coreConfigInjector == null) {
LOG.error("Injector for core configuration could not be created, exiting! (Please include the previous " + "error messages in bug reports.)");
System.exit(1);
}
return coreConfigInjector;
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class FormattedEmailAlertSender method sendEmails.
@Override
public void sendEmails(Stream stream, EmailRecipients recipients, AlertCondition.CheckResult checkResult, List<Message> backlog) throws TransportConfigurationException, EmailException {
if (!configuration.isEnabled()) {
throw new TransportConfigurationException("Email transport is not enabled in server configuration file!");
}
if (recipients == null || recipients.isEmpty()) {
throw new RuntimeException("Cannot send emails: empty recipient list.");
}
final Set<String> recipientsSet = recipients.getEmailRecipients();
if (recipientsSet.size() == 0) {
final Notification notification = notificationService.buildNow().addNode(nodeId.toString()).addType(Notification.Type.GENERIC).addSeverity(Notification.Severity.NORMAL).addDetail("title", "Stream \"" + stream.getTitle() + "\" is alerted, but no recipients have been defined!").addDetail("description", "To fix this, go to the alerting configuration of the stream and add at least one alert recipient.");
notificationService.publishIfFirst(notification);
}
for (String email : recipientsSet) {
sendEmail(email, stream, checkResult, backlog);
}
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration method upgrade.
@Override
public void upgrade() {
if (clusterConfigService.get(MigrationCompleted.class) != null) {
LOG.debug("Migration already completed!");
return;
}
final ImmutableSet.Builder<String> updatedIds = ImmutableSet.builder();
final ImmutableSet.Builder<String> skippedIds = ImmutableSet.builder();
final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
checkState(indexManagementConfig != null, "Couldn't find index management configuration");
for (final IndexSetConfig indexSetConfig : indexSetService.findAll()) {
final IndexSetConfig.Builder updated = indexSetConfig.toBuilder();
if (isNullOrEmpty(indexSetConfig.rotationStrategyClass())) {
// Paranoia
checkState(indexSetConfig.rotationStrategy().type().startsWith(indexManagementConfig.rotationStrategy()), "rotation strategy config type <%s> does not match rotation strategy <%s>", indexSetConfig.rotationStrategy().type(), indexManagementConfig.rotationStrategy());
LOG.info("Adding rotation_strategy_class <{}> to index set <{}>", indexManagementConfig.rotationStrategy(), indexSetConfig.id());
updated.rotationStrategyClass(indexManagementConfig.rotationStrategy());
}
if (isNullOrEmpty(indexSetConfig.retentionStrategyClass())) {
// Paranoia
checkState(indexSetConfig.retentionStrategy().type().startsWith(indexManagementConfig.retentionStrategy()), "retention strategy config type <%s> does not match retention strategy <%s>", indexSetConfig.retentionStrategy().type(), indexManagementConfig.retentionStrategy());
LOG.info("Adding retention_strategy_class <{}> to index set <{}>", indexManagementConfig.retentionStrategy(), indexSetConfig.id());
updated.retentionStrategyClass(indexManagementConfig.retentionStrategy());
}
if (!indexSetConfig.equals(updated.build())) {
indexSetService.save(updated.build());
updatedIds.add(Optional.ofNullable(indexSetConfig.id()).orElseThrow(() -> new IllegalStateException("no id??")));
} else {
skippedIds.add(Optional.ofNullable(indexSetConfig.id()).orElseThrow(() -> new IllegalStateException("no id??")));
}
}
// Mark the oldest index set (there should be only one at this point, though) as default.
final IndexSetConfig defaultIndexSetConfig = indexSetService.findAll().stream().sorted(Comparator.comparing(IndexSetConfig::creationDate)).findFirst().orElseThrow(() -> new IllegalStateException("Unable to find any index set - this should not happen!"));
LOG.info("Setting index set <{}> as default", defaultIndexSetConfig.id());
clusterConfigService.write(DefaultIndexSetConfig.create(defaultIndexSetConfig.id()));
clusterConfigService.write(MigrationCompleted.create(updatedIds.build(), skippedIds.build(), defaultIndexSetConfig.id()));
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class V20161125161400_AlertReceiversMigration method updateConfiguration.
private Optional<String> updateConfiguration(Stream stream, AlarmCallbackConfiguration callbackConfiguration) {
final Map<String, List<String>> alertReceivers = stream.getAlertReceivers();
final List<String> usernames = alertReceivers.get("users");
final List<String> emails = alertReceivers.get("emails");
final Map<String, Object> configuration = callbackConfiguration.getConfiguration();
if (usernames != null && !usernames.isEmpty()) {
LOG.debug("Moving users alert receivers from stream <" + stream.getId() + ">");
configuration.put(EmailAlarmCallback.CK_USER_RECEIVERS, usernames);
}
if (emails != null && !emails.isEmpty()) {
LOG.debug("Moving emails alert receivers from stream <" + stream.getId() + ">");
configuration.put(EmailAlarmCallback.CK_EMAIL_RECEIVERS, emails);
}
final AlarmCallbackConfigurationImpl updatedConfiguration = ((AlarmCallbackConfigurationImpl) callbackConfiguration).toBuilder().setConfiguration(configuration).build();
try {
final String callbackId = this.alarmCallbackService.save(updatedConfiguration);
LOG.debug("Successfully created email alarm callback <" + callbackId + "> for stream <" + stream.getId() + ">.");
return Optional.of(callbackId);
} catch (ValidationException e) {
LOG.error("Unable to create email alarm callback for stream <" + stream.getId() + ">: ", e);
}
return Optional.empty();
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class StreamAlertConditionResource method convertConfigurationInRequest.
private CreateConditionRequest convertConfigurationInRequest(final CreateConditionRequest request) {
final AlertCondition.Factory factory = alertConditionMap.get(request.type());
if (factory == null) {
throw new BadRequestException("Unable to load alert condition of type " + request.type());
}
final ConfigurationRequest requestedConfiguration = factory.config().getRequestedConfiguration();
// coerce the configuration to their correct types according to the condition's requested config
final Map<String, Object> parameters;
try {
parameters = ConfigurationMapConverter.convertValues(request.parameters(), requestedConfiguration);
} catch (ValidationException e) {
throw new BadRequestException("Invalid alert condition parameters", e);
}
return request.toBuilder().setParameters(parameters).build();
}
Aggregations