use of org.graylog2.rest.models.configuration.responses.TextField in project graylog2-server by Graylog2.
the class AbstractInputsResource method maskPasswordsInConfiguration.
protected Map<String, Object> maskPasswordsInConfiguration(Map<String, Object> configuration, ConfigurationRequest configurationRequest) {
if (configuration == null || configurationRequest == null) {
return configuration;
}
return configuration.entrySet().stream().collect(HashMap::new, (map, entry) -> {
final ConfigurationField field = configurationRequest.getField(entry.getKey());
if (field instanceof TextField) {
final TextField textField = (TextField) field;
if (textField.getAttributes().contains(TextField.Attribute.IS_PASSWORD.toString().toLowerCase(Locale.ENGLISH)) && !Strings.isNullOrEmpty((String) entry.getValue())) {
map.put(entry.getKey(), "<password set>");
return;
}
}
map.put(entry.getKey(), entry.getValue());
}, HashMap::putAll);
}
use of org.graylog2.rest.models.configuration.responses.TextField in project graylog2-server by Graylog2.
the class HTTPAlarmCallback method getRequestedConfiguration.
@Override
public ConfigurationRequest getRequestedConfiguration() {
final ConfigurationRequest configurationRequest = new ConfigurationRequest();
configurationRequest.addField(new TextField(CK_URL, "URL", "https://example.org/alerts", "The URL to POST to when an alert is triggered", ConfigurationField.Optional.NOT_OPTIONAL));
return configurationRequest;
}
use of org.graylog2.rest.models.configuration.responses.TextField 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();
if (!graylogConfig.isCloud()) {
configurationRequest.addField(new TextField("sender", "Sender", "", "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;
}
use of org.graylog2.rest.models.configuration.responses.TextField in project graylog2-server by Graylog2.
the class AvailableAlarmCallbackSummaryResponse method extractRequestedConfiguration.
public List<RequestedConfigurationField> extractRequestedConfiguration(Map<String, Map<String, Object>> config) {
List<RequestedConfigurationField> result = Lists.newArrayList();
List<RequestedConfigurationField> booleanFields = Lists.newArrayList();
for (Map.Entry<String, Map<String, Object>> entry : config.entrySet()) {
try {
String fieldType = (String) entry.getValue().get("type");
switch(fieldType) {
case "text":
result.add(new TextField(entry));
continue;
case "number":
result.add(new NumberField(entry));
continue;
case "boolean":
booleanFields.add(new BooleanField(entry));
continue;
case "dropdown":
result.add(new DropdownField(entry));
continue;
default:
LOG.info("Unknown field type [{}].", fieldType);
}
} catch (Exception e) {
LOG.error("Skipping invalid configuration field [" + entry.getKey() + "]", e);
}
}
result.addAll(booleanFields);
return result;
}
use of org.graylog2.rest.models.configuration.responses.TextField in project graylog2-server by Graylog2.
the class ConfigurationRequestTest method addFieldAppendsFieldAtTheEnd.
@Test
public void addFieldAppendsFieldAtTheEnd() throws Exception {
int numberOfFields = 5;
for (int i = 0; i < numberOfFields; i++) {
configurationRequest.addField(new TextField("field" + i, "humanName", "defaultValue", "description"));
}
assertThat(configurationRequest.getFields().keySet()).containsSequence("field0", "field1", "field2", "field3", "field4");
}
Aggregations