use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class IndexRetentionThread method doRun.
@Override
public void doRun() {
if (!cluster.isConnected() || !cluster.isHealthy()) {
LOG.info("Elasticsearch cluster not available, skipping index retention checks.");
return;
}
for (final IndexSet indexSet : indexSetRegistry) {
if (!indexSet.getConfig().isWritable()) {
LOG.debug("Skipping non-writable index set <{}> ({})", indexSet.getConfig().id(), indexSet.getConfig().title());
continue;
}
final IndexSetConfig config = indexSet.getConfig();
final Provider<RetentionStrategy> retentionStrategyProvider = retentionStrategyMap.get(config.retentionStrategyClass());
if (retentionStrategyProvider == null) {
LOG.warn("Retention strategy \"{}\" not found, not running index retention!", config.retentionStrategyClass());
retentionProblemNotification("Index Retention Problem!", "Index retention strategy " + config.retentionStrategyClass() + " not found! Please fix your index retention configuration!");
continue;
}
retentionStrategyProvider.get().retain(indexSet);
}
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class SearchesTest method setUp.
@Before
public void setUp() throws Exception {
when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(INDEX_RANGES);
metricRegistry = new MetricRegistry();
searches = new Searches(new Configuration(), indexRangeService, client, metricRegistry, streamService, mock(Indices.class));
}
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();
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class StreamAlertResource method sendDummyAlert.
@POST
@Timed
@Path("sendDummyAlert")
@ApiOperation(value = "Send a test mail for a given stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 400, message = "Stream has no alarm callbacks") })
@NoAuditEvent("only used to test alert emails")
public void sendDummyAlert(@ApiParam(name = "streamId", value = "The stream id the test alert should be sent for.", required = true) @PathParam("streamId") String streamId) throws TransportConfigurationException, EmailException, NotFoundException {
checkPermission(RestPermissions.STREAMS_EDIT, streamId);
final Stream stream = streamService.load(streamId);
final DummyAlertCondition dummyAlertCondition = new DummyAlertCondition(stream, null, Tools.nowUTC(), getSubject().getPrincipal().toString(), Collections.emptyMap(), "Test Alert");
try {
AbstractAlertCondition.CheckResult checkResult = dummyAlertCondition.runCheck();
List<AlarmCallbackConfiguration> callConfigurations = alarmCallbackConfigurationService.getForStream(stream);
if (callConfigurations.size() == 0) {
final String message = "Stream has no alarm callbacks, cannot send test alert.";
LOG.warn(message);
throw new BadRequestException(message);
}
for (AlarmCallbackConfiguration configuration : callConfigurations) {
AlarmCallback alarmCallback = alarmCallbackFactory.create(configuration);
alarmCallback.call(stream, checkResult);
}
} catch (AlarmCallbackException | ClassNotFoundException | AlarmCallbackConfigurationException e) {
throw new InternalServerErrorException(e.getMessage(), e);
}
}
use of org.graylog2.Configuration in project graylog2-server by Graylog2.
the class StreamAlarmCallbackResource method convertConfigurationValues.
private Map<String, Object> convertConfigurationValues(final CreateAlarmCallbackRequest alarmCallbackRequest) {
final ConfigurationRequest requestedConfiguration;
try {
final AlarmCallback alarmCallback = alarmCallbackFactory.create(alarmCallbackRequest.type());
requestedConfiguration = alarmCallback.getRequestedConfiguration();
} catch (ClassNotFoundException e) {
throw new BadRequestException("Unable to load alarm callback of type " + alarmCallbackRequest.type(), e);
}
// coerce the configuration to their correct types according to the alarmcallback's requested config
final Map<String, Object> configuration;
try {
configuration = ConfigurationMapConverter.convertValues(alarmCallbackRequest.configuration(), requestedConfiguration);
} catch (ValidationException e) {
throw new BadRequestException("Invalid configuration map", e);
}
return configuration;
}
Aggregations