Search in sources :

Example 1 with TextField

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);
}
Also used : HashMap(java.util.HashMap) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField)

Example 2 with TextField

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;
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) TextField(org.graylog2.plugin.configuration.fields.TextField)

Example 3 with TextField

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;
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) TextField(org.graylog2.plugin.configuration.fields.TextField) ListField(org.graylog2.plugin.configuration.fields.ListField)

Example 4 with TextField

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;
}
Also used : DropdownField(org.graylog2.rest.models.configuration.responses.DropdownField) BooleanField(org.graylog2.rest.models.configuration.responses.BooleanField) RequestedConfigurationField(org.graylog2.rest.models.configuration.responses.RequestedConfigurationField) TextField(org.graylog2.rest.models.configuration.responses.TextField) Map(java.util.Map) NumberField(org.graylog2.rest.models.configuration.responses.NumberField)

Example 5 with TextField

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");
}
Also used : TextField(org.graylog2.plugin.configuration.fields.TextField) Test(org.junit.Test)

Aggregations

TextField (org.graylog2.plugin.configuration.fields.TextField)15 Test (org.junit.Test)11 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)10 ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)7 Input (org.graylog2.inputs.Input)4 InputDescription (org.graylog2.shared.inputs.InputDescription)4 HashMap (java.util.HashMap)2 InputSummary (org.graylog2.rest.models.system.inputs.responses.InputSummary)2 InputsList (org.graylog2.rest.models.system.inputs.responses.InputsList)2 Map (java.util.Map)1 UUID (java.util.UUID)1 BooleanField (org.graylog2.plugin.configuration.fields.BooleanField)1 DropdownField (org.graylog2.plugin.configuration.fields.DropdownField)1 ListField (org.graylog2.plugin.configuration.fields.ListField)1 NumberField (org.graylog2.plugin.configuration.fields.NumberField)1 BooleanField (org.graylog2.rest.models.configuration.responses.BooleanField)1 DropdownField (org.graylog2.rest.models.configuration.responses.DropdownField)1 NumberField (org.graylog2.rest.models.configuration.responses.NumberField)1 RequestedConfigurationField (org.graylog2.rest.models.configuration.responses.RequestedConfigurationField)1 TextField (org.graylog2.rest.models.configuration.responses.TextField)1