Search in sources :

Example 1 with ConfigurationRequest

use of org.graylog2.plugin.configuration.ConfigurationRequest 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 2 with ConfigurationRequest

use of org.graylog2.plugin.configuration.ConfigurationRequest 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)

Example 3 with ConfigurationRequest

use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.

the class V20161125142400_EmailAlarmCallbackMigrationTest method extractEmptyDefaultValuesFromEmptyEmailAlarmCallbackConfiguration.

@Test
public void extractEmptyDefaultValuesFromEmptyEmailAlarmCallbackConfiguration() throws Exception {
    final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
    when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
    final Map<String, Object> defaultConfig = this.emailAlarmCallbackMigrationPeriodical.getDefaultEmailAlarmCallbackConfig();
    assertThat(defaultConfig).isNotNull().isEmpty();
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) Test(org.junit.Test)

Example 4 with ConfigurationRequest

use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.

the class HttpTransportConfigTest method testGetRequestedConfiguration.

@Test
public void testGetRequestedConfiguration() throws Exception {
    HttpTransport.Config config = new HttpTransport.Config();
    final ConfigurationRequest requestedConfiguration = config.getRequestedConfiguration();
    assertTrue(requestedConfiguration.containsField(HttpTransport.CK_ENABLE_CORS));
    assertEquals(requestedConfiguration.getField(HttpTransport.CK_ENABLE_CORS).isOptional(), ConfigurationField.Optional.OPTIONAL);
    assertEquals(requestedConfiguration.getField(HttpTransport.CK_ENABLE_CORS).getDefaultValue(), true);
    assertTrue(requestedConfiguration.containsField(HttpTransport.CK_MAX_CHUNK_SIZE));
    assertEquals(requestedConfiguration.getField(HttpTransport.CK_MAX_CHUNK_SIZE).isOptional(), ConfigurationField.Optional.OPTIONAL);
    assertEquals(requestedConfiguration.getField(HttpTransport.CK_MAX_CHUNK_SIZE).getDefaultValue(), 65536);
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) Test(org.junit.Test)

Example 5 with ConfigurationRequest

use of org.graylog2.plugin.configuration.ConfigurationRequest in project graylog2-server by Graylog2.

the class EmailAlarmCallback method getConfigurationRequest.

// I am truly sorry about this, but leaking the user list is not okay...
private ConfigurationRequest getConfigurationRequest(Map<String, String> userNames) {
    ConfigurationRequest configurationRequest = new ConfigurationRequest();
    configurationRequest.addField(new TextField("sender", "Sender", "graylog@example.org", "The sender of sent out mail alerts", ConfigurationField.Optional.OPTIONAL));
    configurationRequest.addField(new TextField("subject", "E-Mail Subject", "Graylog alert for stream: ${stream.title}: ${check_result.resultDescription}", "The subject of sent out mail alerts", ConfigurationField.Optional.NOT_OPTIONAL));
    configurationRequest.addField(new TextField("body", "E-Mail Body", FormattedEmailAlertSender.bodyTemplate, "The template to generate the body from", ConfigurationField.Optional.OPTIONAL, TextField.Attribute.TEXTAREA));
    configurationRequest.addField(new ListField(CK_USER_RECEIVERS, "User Receivers", Collections.emptyList(), userNames, "Graylog usernames that should receive this alert", ConfigurationField.Optional.OPTIONAL));
    configurationRequest.addField(new ListField(CK_EMAIL_RECEIVERS, "E-Mail Receivers", Collections.emptyList(), Collections.emptyMap(), "E-Mail addresses that should receive this alert", ConfigurationField.Optional.OPTIONAL, ListField.Attribute.ALLOW_CREATE));
    return configurationRequest;
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) TextField(org.graylog2.plugin.configuration.fields.TextField) ListField(org.graylog2.plugin.configuration.fields.ListField)

Aggregations

ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)18 Test (org.junit.Test)11 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)4 HashMap (java.util.HashMap)3 TextField (org.graylog2.plugin.configuration.fields.TextField)3 ValidationException (org.graylog2.plugin.database.ValidationException)3 BadRequestException (javax.ws.rs.BadRequestException)2 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)2 ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)2 Stream (org.graylog2.plugin.streams.Stream)2 CreateAlarmCallbackRequest (org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest)2 Maps (com.google.common.collect.Maps)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 EmailAlarmCallback (org.graylog2.alarmcallbacks.EmailAlarmCallback)1 AlarmCallback (org.graylog2.plugin.alarms.callbacks.AlarmCallback)1 Configuration (org.graylog2.plugin.configuration.Configuration)1