diff --git a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/mapping/AbstractLogstashPluginAttributesMapper.java b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/mapping/AbstractLogstashPluginAttributesMapper.java index 555c30de1f..fae7e26050 100644 --- a/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/mapping/AbstractLogstashPluginAttributesMapper.java +++ b/data-prepper-logstash-configuration/src/main/java/org/opensearch/dataprepper/logstash/mapping/AbstractLogstashPluginAttributesMapper.java @@ -37,18 +37,16 @@ public Map mapAttributes(final List logstashA .filter(logstashAttribute -> !customMappedAttributeNames.contains(logstashAttribute.getAttributeName())) .forEach(logstashAttribute -> { final String logstashAttributeName = logstashAttribute.getAttributeName(); + final String dataPrepperAttributeName = mappedAttributeNames.get(logstashAttributeName); if (mappedAttributeNames.containsKey(logstashAttributeName)) { - if (mappedAttributeNames.get(logstashAttributeName).startsWith("!")) { + if (dataPrepperAttributeName.startsWith("!") && logstashAttribute.getAttributeValue().getValue() instanceof Boolean) { pluginSettings.put( - mappedAttributeNames.get(logstashAttributeName).substring(1), - !(Boolean) logstashAttribute.getAttributeValue().getValue() + dataPrepperAttributeName.substring(1), !(Boolean) logstashAttribute.getAttributeValue().getValue() ); } else { - pluginSettings.put( - mappedAttributeNames.get(logstashAttributeName), - logstashAttribute.getAttributeValue().getValue()); + pluginSettings.put(dataPrepperAttributeName, logstashAttribute.getAttributeValue().getValue()); } } else { diff --git a/data-prepper-logstash-configuration/src/main/resources/org/opensearch/dataprepper/logstash/mapping/opensearch.mapping.yaml b/data-prepper-logstash-configuration/src/main/resources/org/opensearch/dataprepper/logstash/mapping/opensearch.mapping.yaml index c4e170efb3..5f0fec03c0 100644 --- a/data-prepper-logstash-configuration/src/main/resources/org/opensearch/dataprepper/logstash/mapping/opensearch.mapping.yaml +++ b/data-prepper-logstash-configuration/src/main/resources/org/opensearch/dataprepper/logstash/mapping/opensearch.mapping.yaml @@ -4,4 +4,4 @@ mappedAttributeNames: user: username password: password index: index - ssl_certificate_verification: !insecure \ No newline at end of file + ssl_certificate_verification: "!insecure" \ No newline at end of file diff --git a/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/mapping/DefaultLogstashPluginAttributesMapperTest.java b/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/mapping/DefaultLogstashPluginAttributesMapperTest.java index 9fbd974b9d..bf0619dd39 100644 --- a/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/mapping/DefaultLogstashPluginAttributesMapperTest.java +++ b/data-prepper-logstash-configuration/src/test/java/org/opensearch/dataprepper/logstash/mapping/DefaultLogstashPluginAttributesMapperTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.opensearch.dataprepper.logstash.model.LogstashAttribute; import org.opensearch.dataprepper.logstash.model.LogstashAttributeValue; @@ -116,19 +118,18 @@ void mapAttributes_sets_additional_attributes_to_those_values() { assertThat(actualPluginSettings.get(additionalAttributeName), equalTo(additionalAttributeValue)); } - @Test - void mapAttributes_with_negation_expression_negates_boolean_value() { + @ParameterizedTest + @ValueSource(booleans = { true, false } ) + void mapAttributes_with_negation_expression_negates_boolean_value(boolean inputValue) { final String dataPrepperAttribute = "!".concat(UUID.randomUUID().toString()); - boolean value = true; - when(logstashAttributeValue.getValue()).thenReturn(value); + when(logstashAttributeValue.getValue()).thenReturn(inputValue); when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(logstashAttributeName, dataPrepperAttribute)); - final Map actualPluginSettings = - createObjectUnderTest().mapAttributes(logstashAttributes, mappings); + final Map actualPluginSettings = createObjectUnderTest().mapAttributes(logstashAttributes, mappings); assertThat(actualPluginSettings, notNullValue()); assertThat(actualPluginSettings.size(), equalTo(1)); - assertThat(actualPluginSettings.get(dataPrepperAttribute.substring(1)), equalTo(!value)); + assertThat(actualPluginSettings.get(dataPrepperAttribute.substring(1)), equalTo(!inputValue)); } } \ No newline at end of file diff --git a/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch-insecure.expected.yaml b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch-insecure.expected.yaml new file mode 100644 index 0000000000..4050cab6bb --- /dev/null +++ b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch-insecure.expected.yaml @@ -0,0 +1,18 @@ +logstash-converted-pipeline: + source: + http: + max_connection_count: 500 + request_timeout: 10000 + processor: + - grok: + match: + log: + - "%{COMBINEDAPACHELOG}" + sink: + - opensearch: + hosts: + - "fakedomain.us-east-1.es.amazonaws.com" + username: "myuser" + password: "mypassword" + index: "my-index" + insecure: true diff --git a/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch.conf b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch.conf new file mode 100644 index 0000000000..acad6f6cd3 --- /dev/null +++ b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch.conf @@ -0,0 +1,18 @@ +input { + http { + } +} +filter { + grok { + match => {"log" => "%{COMBINEDAPACHELOG}"} + } +} +output { + opensearch { + hosts => ["fakedomain.us-east-1.es.amazonaws.com"] + user => myuser + password => mypassword + index => "my-index" + ssl_certificate_verification => true + } +} \ No newline at end of file diff --git a/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch.expected.yaml b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch.expected.yaml new file mode 100644 index 0000000000..618dddeaf0 --- /dev/null +++ b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logstash-opensearch.expected.yaml @@ -0,0 +1,18 @@ +logstash-converted-pipeline: + source: + http: + max_connection_count: 500 + request_timeout: 10000 + processor: + - grok: + match: + log: + - "%{COMBINEDAPACHELOG}" + sink: + - opensearch: + hosts: + - "fakedomain.us-east-1.es.amazonaws.com" + username: "myuser" + password: "mypassword" + index: "my-index" + insecure: false diff --git a/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logtstash-opensearch-insecure.conf b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logtstash-opensearch-insecure.conf new file mode 100644 index 0000000000..4c08eb5da0 --- /dev/null +++ b/data-prepper-logstash-configuration/src/test/resources/org/opensearch/dataprepper/logstash/log-ingest-to-logtstash-opensearch-insecure.conf @@ -0,0 +1,18 @@ +input { + http { + } +} +filter { + grok { + match => {"log" => "%{COMBINEDAPACHELOG}"} + } +} +output { + opensearch { + hosts => ["fakedomain.us-east-1.es.amazonaws.com"] + user => myuser + password => mypassword + index => "my-index" + ssl_certificate_verification => false + } +} \ No newline at end of file