Skip to content

Commit

Permalink
Updated support for negating boolean logstash attribute value
Browse files Browse the repository at this point in the history
Signed-off-by: Asif Sohail Mohammed <[email protected]>
  • Loading branch information
asifsmohammed committed Dec 21, 2021
1 parent a429acc commit 84eaa84
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ public Map<String, Object> mapAttributes(final List<LogstashAttribute> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mappedAttributeNames:
user: username
password: password
index: index
ssl_certificate_verification: !insecure
ssl_certificate_verification: "!insecure"
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, Object> actualPluginSettings =
createObjectUnderTest().mapAttributes(logstashAttributes, mappings);
final Map<String, Object> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 84eaa84

Please sign in to comment.