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