Search in sources :

Example 6 with Configuration

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);
    }
}
Also used : RetentionStrategy(org.graylog2.plugin.indexer.retention.RetentionStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) IndexSet(org.graylog2.indexer.IndexSet)

Example 7 with Configuration

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));
}
Also used : Configuration(org.graylog2.Configuration) MetricRegistry(com.codahale.metrics.MetricRegistry) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) Before(org.junit.Before)

Example 8 with Configuration

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();
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) BadRequestException(javax.ws.rs.BadRequestException)

Example 9 with Configuration

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);
    }
}
Also used : AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Stream(org.graylog2.plugin.streams.Stream) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) DummyAlertCondition(org.graylog2.alerts.types.DummyAlertCondition) AlarmCallbackException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 10 with Configuration

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;
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) BadRequestException(javax.ws.rs.BadRequestException) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback)

Aggregations

Test (org.junit.Test)36 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