Search in sources :

Example 1 with TextField

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

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

Example 3 with TextField

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

the class ConfigurationRequestTest method putAllRetainsOrder.

@Test
public void putAllRetainsOrder() throws Exception {
    final ImmutableMap<String, ConfigurationField> fields = ImmutableMap.<String, ConfigurationField>of("field1", new TextField("field1", "humanName", "defaultValue", "description"), "field2", new TextField("field2", "humanName", "defaultValue", "description"), "field3", new TextField("field3", "humanName", "defaultValue", "description"));
    configurationRequest.putAll(fields);
    assertThat(configurationRequest.getFields().keySet()).containsSequence("field1", "field2", "field3");
}
Also used : ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField) Test(org.junit.Test)

Example 4 with TextField

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

Example 5 with TextField

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

Aggregations

TextField (org.graylog2.plugin.configuration.fields.TextField)6 Test (org.junit.Test)4 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 BooleanField (org.graylog2.plugin.configuration.fields.BooleanField)1 ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)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