You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/12/07 22:56:44 UTC
[GitHub] [nifi] simonbence opened a new pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
simonbence opened a new pull request #4714:
URL: https://github.com/apache/nifi/pull/4714
[NIFI-7801](https://issues.apache.org/jira/browse/NIFI-7801)
This is my proposal for support HTTP based Splunk put with HEC Index Acknowledgement. This later makes it possible to build flows capable to wait for Splunk acknowledgement. This is reached with introducing two new processors, PutSplunkHTTP and QuerySplunkIndexingStatus.
PutSplunkHTTP provides a similar functionality as PutSplunk, just instead of TCP/UDP, it uses HTTP as transfer protocol. Because of the structure of PutSplunk, it was not strait-forward to extend that, and also InvokeHTTP was not capable to cover the functionality.
QuerySplunkIndexingStatus is the other added processor, responsible for looking after the indexing acknowledgements after PutSplunkHTTP. It is optional, without it the behaviour is similar as in case of PutSplunk. Both processors are built around the Service class provided by the Splunk library just as in case of GetSplunk.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [ ] Does your PR title start with **NIFI-XXXX** where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [ ] Has your PR been rebased against the latest commit within the target branch (typically `main`)?
- [ ] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
### For code changes:
- [ ] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] Have you verified that the full build is successful on JDK 8?
- [ ] Have you verified that the full build is successful on JDK 11?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the `LICENSE` file, including the main `LICENSE` file under `nifi-assembly`?
- [ ] If applicable, have you updated the `NOTICE` file, including the main `NOTICE` file found under `nifi-assembly`?
- [ ] If adding new Properties, have you added `.displayName` in addition to .name (programmatic access) for each of the new properties?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] tpalfy commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r543488603
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.HttpException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
Review comment:
Minor: `toString()` instead of `name()` could be more appropriate for `displayName`.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/dto/splunk/SendRawDataResponse.java
##########
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.dto.splunk;
+
+/**
+ * Response object for sending raw data directly to HTTP Event Collecto in Splunk.
Review comment:
Probably a typo: `Collecto` -> `Collector`
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: {}", new Object[] {e.getMessage()}, e);
+ } finally {
+ session.transfer(flowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
+ return requestMessage;
+ }
+
+ private String extractTextMessageBody(final FlowFile flowFile, final ProcessSession session, final String charset) {
+ final StringWriter writer = new StringWriter();
+ session.read(flowFile, in -> IOUtils.copy(in, writer, Charset.forName(charset)));
+ return writer.toString();
+ }
+
+ private FlowFile enrichFlowFile(final ProcessSession session, final FlowFile flowFile, final long ackId) {
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE, String.valueOf(ackId));
+ attributes.put(SplunkAPICall.SENT_AT_ATTRIBUTE, String.valueOf(System.currentTimeMillis()));
Review comment:
In reality this is more like when the response came back instead of when the message was sent. Not sure if the difference matters. Is this intentional?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
Review comment:
```suggestion
.description("A FlowFile is transferred to this relationship when the acknowledgement was not successful.")
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
Review comment:
```suggestion
.description("FlowFiles that are sent successfully to the destination are sent to this relationship.")
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
Review comment:
```suggestion
.description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: {}", new Object[] {e.getMessage()}, e);
+ } finally {
+ session.transfer(flowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
Review comment:
There is a `requestMessage.setContent` that accepts an `OutputStream` instead of a `String`. Seems a better approach considering the typical use-cases of NiFi.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
Review comment:
Could we add some clarification how this differs from `unacknowledged`? Refer to `Maximum Waiting Time` property with a simple explanation for example.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
Review comment:
This sentence seems to lack a predicate. Maybe
```suggestion
"The maximum number of acknowledgement identifiers the service query status(?) contains in one batch. " +
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized! " +
Review comment:
```suggestion
"A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
"Flow files transferred to this relationship might be penalized! " +
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
Review comment:
```suggestion
"It is recommended not to set it too low in order to reduce network communication.")
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.SENT_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.SENT_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(ackId.get(), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().debug("There was no eligible flow file to send request to Splunk.");
+ return;
+ }
+
+ try {
+ requestMessage = createRequestMessage(undetermined);
+ } catch (final IOException e) {
+ getLogger().error("Could not prepare Splunk request!", e);
+ session.transfer(undetermined.values(), RELATIONSHIP_FAILURE);
+ return;
+ }
+
+ try {
+ final ResponseMessage responseMessage = call(ENDPOINT, requestMessage);
+
+ if (responseMessage.getStatus() == 200) {
+ final EventIndexStatusResponse splunkResponse = unmarshallResult(responseMessage.getContent(), EventIndexStatusResponse.class);
+
+ splunkResponse.getAcks().entrySet().forEach(result -> {
+ final FlowFile toTransfer = undetermined.get(result.getKey());
+
+ if (result.getValue()) {
+ session.transfer(toTransfer, RELATIONSHIP_ACKNOWLEDGED);
+ } else {
+ session.penalize(toTransfer);
+ session.transfer(toTransfer, RELATIONSHIP_UNDETERMINED);
+ }
+ });
+ } else {
+ getLogger().error("Query index status was not successful because of ({}) {}", new Object[] {responseMessage.getStatus(), responseMessage.getContent()});
+ context.yield();
+ session.transfer(undetermined.values(), RELATIONSHIP_UNDETERMINED);
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk server!", e);
+ session.transfer(undetermined.values(), RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(Map<Long, FlowFile> undetermined) throws IOException {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ requestMessage.getHeader().put("Content-Type", "application/json");
+ requestMessage.setContent(generateContent(undetermined));
+ return requestMessage;
+ }
+
+ private String generateContent(final Map<Long, FlowFile> undetermined) throws IOException {
+ final EventIndexStatusRequest splunkRequest = new EventIndexStatusRequest();
+ splunkRequest.setAcks(new ArrayList<>(undetermined.keySet()));
+ return marshalRequest(splunkRequest);
+ }
+
+ private static Optional<Long> extractLong(final String value) {
+ if (value == null) {
+ return Optional.empty();
+ }
+
+ try {
+ return Optional.of(Long.valueOf(value));
+ } catch (final NumberFormatException e) {
+ return Optional.empty();
+ }
Review comment:
```suggestion
try {
return Optional.ofNullable(value).map(Long::valueOf);
} catch (final NumberFormatException e) {
return Optional.empty();
}
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
Review comment:
Not really clear what `output buffer` means here. Is it the `failure` relationship itself? If that's the case, why not state that instead?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
Review comment:
```suggestion
.description("FlowFiles that failed to send to the destination are sent to this relationship.")
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
Review comment:
Suggestion: A main cause of exception could be being unable to unmarshall the result. It may be a good idea to log the response content in that case.
Note: For that we would need to know if the unmarshall was successful. Response could be declared before the switch block and checked if it is null here - however response can be of two different type.
Not entirely sure why it is better to have two types instead of one though. A single type with nullable `ackId` could work.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539462655
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ if (splunkService != null) {
+ splunkService.logout();
+ splunkService = null;
+ }
+
+ requestChannel = null;
+ ackIdAttributeName = null;
+ insertedAtAttributeName = null;
+ splunkServiceArguments = null;
+ }
+
+ protected ResponseMessage call(final String endpoint, final RequestMessage request) {
+ request.getHeader().put(REQUEST_CHANNEL_HEADER_NAME, requestChannel);
+
+ try {
+ return splunkService.send(endpoint, request);
+ //Catch Stale connection exception, reinitialize, and retry
+ } catch (final com.splunk.HttpException e) {
Review comment:
Fair point, it's a shared logic with GetSplunk and remained like this. Fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] markap14 closed pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
markap14 closed pull request #4714:
URL: https://github.com/apache/nifi/pull/4714
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539460500
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
Review comment:
Again: this is the way GetSplunk offers security and I see risk in moving into different direction in the same processor family. My consideration is similar: I find your comment valid but I would prefer to aim this in a separate story.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539448810
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
Review comment:
In some cases Service does encode it, but I double-checked, not this case, thanks!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r538744071
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
Review comment:
The Splunk Service object has a setSSLSocketFactory method that would allow leveraging the NiFi StandardRestrictedSSLContextService instead of providing custom SSL properties. Did you evaluate using that method instead of providing this Security Protocol property?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ if (splunkService != null) {
+ splunkService.logout();
+ splunkService = null;
+ }
+
+ requestChannel = null;
+ ackIdAttributeName = null;
+ insertedAtAttributeName = null;
+ splunkServiceArguments = null;
+ }
+
+ protected ResponseMessage call(final String endpoint, final RequestMessage request) {
+ request.getHeader().put(REQUEST_CHANNEL_HEADER_NAME, requestChannel);
+
+ try {
+ return splunkService.send(endpoint, request);
+ //Catch Stale connection exception, reinitialize, and retry
+ } catch (final com.splunk.HttpException e) {
Review comment:
Is there a reason for using the qualified class as opposed to importing it?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/test/java/org/apache/nifi/processors/splunk/TestQuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestQuerySplunkIndexingStatus {
+ private static final String EVENT = "{\"a\"=\"b\",\"c\"=\"d\",\"e\"=\"f\"}";
+
+ @Mock
+ private Service service;
+
+ @Mock
+ private ResponseMessage response;
+
+ private MockedQuerySplunkIndexingStatus processor;
+ private TestRunner testRunner;
+
+ private ArgumentCaptor<String> path;
+ private ArgumentCaptor<RequestMessage> request;
+
+ @Before
+ public void setUp() {
+ processor = new MockedQuerySplunkIndexingStatus(service);
+ testRunner = TestRunners.newTestRunner(processor);
+ testRunner.setProperty(SplunkAPICall.SCHEME, "http");
+ testRunner.setProperty(SplunkAPICall.TOKEN, "Splunk 888c5a81-8777-49a0-a3af-f76e050ab5d9");
+ testRunner.setProperty(SplunkAPICall.REQUEST_CHANNEL, "22bd7414-0d77-4c73-936d-c8f5d1b21862");
+
+ path = ArgumentCaptor.forClass(String.class);
+ request = ArgumentCaptor.forClass(RequestMessage.class);
+ Mockito.when(service.send(path.capture(), request.capture())).thenReturn(response);
+ }
+
+ @After
+ public void tearDown() {
+ testRunner.shutdown();
+ }
+
+ @Test
+ public void testHappyPath() throws Exception {
Review comment:
Recommend renaming to testRunSuccess()
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
Review comment:
Recommend eliminating TLSv1 and SSLv3 as options since they are generally considered to vulnerable protocols. SSLv3 is also disabled on most recent Java installations, so it may not work even if selected. As mentioned in a separate comment, refactoring to leverage the NiFi SSLContextService would delegate the protocol selection to that service as opposed to introducing options specific to this Processor.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
Review comment:
Although the Scheme, Hostname, and Port properties mirror the options for the Splunk Service, did you consider providing the NiFi property definition as a URL? Providing the NiFi property as a URL would still allow for retrieving the scheme, hostname, and port elements for instantiation, and could also simplify the NiFi Processor configuration.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ if (splunkService != null) {
+ splunkService.logout();
+ splunkService = null;
+ }
+
+ requestChannel = null;
+ ackIdAttributeName = null;
+ insertedAtAttributeName = null;
+ splunkServiceArguments = null;
+ }
+
+ protected ResponseMessage call(final String endpoint, final RequestMessage request) {
+ request.getHeader().put(REQUEST_CHANNEL_HEADER_NAME, requestChannel);
+
+ try {
+ return splunkService.send(endpoint, request);
+ //Catch Stale connection exception, reinitialize, and retry
+ } catch (final com.splunk.HttpException e) {
+ getLogger().error("Splunk request status code:" + e.getStatus() + " Retrying the request.");
Review comment:
Recommend adjusting the logging statement to use parameters:
```suggestion
getLogger().error("Splunk failed with HTTP {}: Retrying the request", new Object[]{ e.getStatus() });
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ if (splunkService != null) {
+ splunkService.logout();
+ splunkService = null;
+ }
+
+ requestChannel = null;
+ ackIdAttributeName = null;
+ insertedAtAttributeName = null;
+ splunkServiceArguments = null;
+ }
+
+ protected ResponseMessage call(final String endpoint, final RequestMessage request) {
+ request.getHeader().put(REQUEST_CHANNEL_HEADER_NAME, requestChannel);
+
+ try {
+ return splunkService.send(endpoint, request);
+ //Catch Stale connection exception, reinitialize, and retry
+ } catch (final com.splunk.HttpException e) {
+ getLogger().error("Splunk request status code:" + e.getStatus() + " Retrying the request.");
+ splunkService.logout();
+ splunkService = getSplunkService(splunkServiceArguments);
+ return splunkService.send(endpoint, request);
+ }
+ }
+
+ protected <T> T extractResult(final InputStream responseBody, final Class<T> type) throws IOException {
+ final JsonParser jsonParser = jsonFactory.createParser(responseBody);
+ jsonParser.setCodec(jsonObjectMapper);
+ return jsonParser.readValueAs(type);
Review comment:
Is there a reason for not using `jsonObjectMapper.readValue(responseBody, type)`?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539461551
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
Review comment:
That was my first attempt (functionally it was okay) but it would show a very different parameter set as GetSplunk that it would be confusing.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] markap14 commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
markap14 commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r563904084
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
Review comment:
No reason to add an exclamation mark here - it is a very normal thing. Under what conditions would they be penalized? An indication that they "might be penalized" leaves me with more questions than answers, as a user.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
Review comment:
nit: Missing a space after the period.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.RESPONDED_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.RESPONDED_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
Review comment:
This seems like the wrong behavior to me. If the data is put to splunk, and then sent to this processor, but sits in the queue for a while (due to the processor being stopped or having a long backlog, etc.) then the FlowFile will immediately go to Unacknowledged, even though Splunk was never queried for the status. Are we sure that's what we want to happen here?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent to this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent to this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
Review comment:
Probably should rename method to `onStopped` instead of `onUnscheduled`
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
Review comment:
Probably should name the method `onStopped` rather than `onUnscheduled`.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.QuerySplunkIndexingStatus/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>QuerySplunkIndexingStatus</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>QuerySplunkIndexingStatus</h2>
+
+<p>
+ This processor is responsible for polling Splunk server and determine if a Splunk event is acknowledged at the time of
+ execution. For more details about the HEC Index Acknowledgement please see
+ <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/Data/AboutHECIDXAck">this documentation.</a>
+</p>
+
+<h3>Prerequisites</h3>
+
+<p>
+ In order to work properly, the incoming flow files need to have the attributes "splunk.acknowledgement.id" and
+ "splunk.responded.at" filled properly. The flow file attribute "splunk.acknowledgement.id" should continue the "ackId"
+ contained by the response of the Splunk from the original put call. The flow file attribute "splunk.responded.at"
+ should contain the Unix Epoch the put call was answered by Splunk. It is suggested to use PutSplunkHTTP processor to execute
+ the put call and set these attributes.
+</p>
+
+<h3>Unacknowledged and undetermined cases</h3>
+
+<p>
+ Splunk serves information only about successful acknowledgement. In every other case it will return a false value. This
Review comment:
Referring to this here as a "false value" makes it sound like a "fake value" or an "invalid value". Would recommend instead "... it will return a value of <code>false</code>."
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.HttpException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final String ACKNOWLEDGEMENT_ID_ATTRIBUTE = "splunk.acknowledgement.id";
+ static final String RESPONDED_AT_ATTRIBUTE = "splunk.responded.at";
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL
+ );
+
+ private final JsonFactory jsonFactory = new JsonFactory();
+ private final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ private volatile ServiceArgs splunkServiceArguments;
+ private volatile Service splunkService;
+ private volatile String requestChannel;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
Review comment:
Should rename method to `onStopped`
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
Review comment:
Not entirely sure what is being said here. "with a false response" sounds like the Splunk server is responding with an invalid or a "fake" response. Perhaps rephrasing to something along the lines of "but with a response indicating that the id has not been acknowledged"? I *think* that's what this is intended to convey.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.PutSplunkHTTP/additionalDetails.html
##########
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>PutSplunkHTTP</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>PutSplunkHTTP</h2>
+
+<p>
+ This processor serves as a counterpart for PutSplunk processor. While the later solves communication using TCP and
+ UDP protocols, PutSplunkHTTP aims to send events into Splunk via HTTP or HTTPS. In this fashion, this processor
+ shows similarities with GetSplunk processor and the properties relevant to the connection with Splunk server are
+ identical. There are however some aspects unique for this processor:
+</p>
+
+<h3>Content details</h3>
+
+<p>
+ PutSplunkHTTP allows the user to specify some metadata about the event is being sent to the Splunk. These include: the
Review comment:
typo: should be "some metadata about the event being sent" - reads "some metadata about the event _is_ being sent"
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.RESPONDED_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.RESPONDED_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(ackId.get(), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().debug("There was no eligible flow file to send request to Splunk.");
+ return;
+ }
+
+ try {
+ requestMessage = createRequestMessage(undetermined);
+ } catch (final IOException e) {
+ getLogger().error("Could not prepare Splunk request!", e);
+ session.transfer(undetermined.values(), RELATIONSHIP_FAILURE);
+ return;
+ }
+
+ try {
+ final ResponseMessage responseMessage = call(ENDPOINT, requestMessage);
+
+ if (responseMessage.getStatus() == 200) {
+ final EventIndexStatusResponse splunkResponse = unmarshallResult(responseMessage.getContent(), EventIndexStatusResponse.class);
+
+ splunkResponse.getAcks().entrySet().forEach(result -> {
+ final FlowFile toTransfer = undetermined.get(result.getKey());
+
+ if (result.getValue()) {
+ session.transfer(toTransfer, RELATIONSHIP_ACKNOWLEDGED);
+ } else {
+ session.penalize(toTransfer);
+ session.transfer(toTransfer, RELATIONSHIP_UNDETERMINED);
+ }
+ });
+ } else {
+ getLogger().error("Query index status was not successful because of ({}) {}", new Object[] {responseMessage.getStatus(), responseMessage.getContent()});
+ context.yield();
+ session.transfer(undetermined.values(), RELATIONSHIP_UNDETERMINED);
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk server!", e);
Review comment:
Would generally recommend against exclamation points in logs
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.QuerySplunkIndexingStatus/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>QuerySplunkIndexingStatus</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>QuerySplunkIndexingStatus</h2>
+
+<p>
+ This processor is responsible for polling Splunk server and determine if a Splunk event is acknowledged at the time of
+ execution. For more details about the HEC Index Acknowledgement please see
+ <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/Data/AboutHECIDXAck">this documentation.</a>
+</p>
+
+<h3>Prerequisites</h3>
+
+<p>
+ In order to work properly, the incoming flow files need to have the attributes "splunk.acknowledgement.id" and
+ "splunk.responded.at" filled properly. The flow file attribute "splunk.acknowledgement.id" should continue the "ackId"
+ contained by the response of the Splunk from the original put call. The flow file attribute "splunk.responded.at"
+ should contain the Unix Epoch the put call was answered by Splunk. It is suggested to use PutSplunkHTTP processor to execute
+ the put call and set these attributes.
+</p>
+
+<h3>Unacknowledged and undetermined cases</h3>
+
+<p>
+ Splunk serves information only about successful acknowledgement. In every other case it will return a false value. This
+ includes unsuccessful or ongoing indexing and unknown acknowledgement identifiers. In order to avoid infinite tries,
+ QuerySplunkIndexingStatus gives user the possibility to set a "Maximum waiting time". False results from Splunk within
+ the specified waiting time will be handled as "undetermined" and are transferred to the "undetermined" relationship.
+ Flow files outside of this time range will be transferred to the "unacknowledged" relationship next time the processor is
+ triggered. In order to determine if the indexing of a given event is within the waiting time, the Unix Epoch stored in
+ the attribute specified by "Splunk Sent At Attribute Name" will be used. Setting "Maximum waiting time" too low might
Review comment:
I don't see a "Splunk Sent At Attribute Name" anywhere. Was this removed? If so, should update the docs.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: {}", new Object[] {e.getMessage()}, e);
+ } finally {
+ session.transfer(flowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
Review comment:
Thanks for that clarification. Probably makes sense to put a comment to that effect in the code so that it's understood later, as well.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] markap14 commented on pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
markap14 commented on pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#issuecomment-740642509
Will Review.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] markap14 commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
markap14 commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r563904084
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
Review comment:
No reason to add an exclamation mark here - it is a very normal thing. Under what conditions would they be penalized? An indication that they "might be penalized" leaves me with more questions than answers, as a user.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
Review comment:
nit: Missing a space after the period.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.RESPONDED_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.RESPONDED_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
Review comment:
This seems like the wrong behavior to me. If the data is put to splunk, and then sent to this processor, but sits in the queue for a while (due to the processor being stopped or having a long backlog, etc.) then the FlowFile will immediately go to Unacknowledged, even though Splunk was never queried for the status. Are we sure that's what we want to happen here?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent to this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent to this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
Review comment:
Probably should rename method to `onStopped` instead of `onUnscheduled`
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
Review comment:
Probably should name the method `onStopped` rather than `onUnscheduled`.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.QuerySplunkIndexingStatus/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>QuerySplunkIndexingStatus</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>QuerySplunkIndexingStatus</h2>
+
+<p>
+ This processor is responsible for polling Splunk server and determine if a Splunk event is acknowledged at the time of
+ execution. For more details about the HEC Index Acknowledgement please see
+ <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/Data/AboutHECIDXAck">this documentation.</a>
+</p>
+
+<h3>Prerequisites</h3>
+
+<p>
+ In order to work properly, the incoming flow files need to have the attributes "splunk.acknowledgement.id" and
+ "splunk.responded.at" filled properly. The flow file attribute "splunk.acknowledgement.id" should continue the "ackId"
+ contained by the response of the Splunk from the original put call. The flow file attribute "splunk.responded.at"
+ should contain the Unix Epoch the put call was answered by Splunk. It is suggested to use PutSplunkHTTP processor to execute
+ the put call and set these attributes.
+</p>
+
+<h3>Unacknowledged and undetermined cases</h3>
+
+<p>
+ Splunk serves information only about successful acknowledgement. In every other case it will return a false value. This
Review comment:
Referring to this here as a "false value" makes it sound like a "fake value" or an "invalid value". Would recommend instead "... it will return a value of <code>false</code>."
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.HttpException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final String ACKNOWLEDGEMENT_ID_ATTRIBUTE = "splunk.acknowledgement.id";
+ static final String RESPONDED_AT_ATTRIBUTE = "splunk.responded.at";
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL
+ );
+
+ private final JsonFactory jsonFactory = new JsonFactory();
+ private final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ private volatile ServiceArgs splunkServiceArguments;
+ private volatile Service splunkService;
+ private volatile String requestChannel;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
Review comment:
Should rename method to `onStopped`
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
Review comment:
Not entirely sure what is being said here. "with a false response" sounds like the Splunk server is responding with an invalid or a "fake" response. Perhaps rephrasing to something along the lines of "but with a response indicating that the id has not been acknowledged"? I *think* that's what this is intended to convey.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.PutSplunkHTTP/additionalDetails.html
##########
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>PutSplunkHTTP</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>PutSplunkHTTP</h2>
+
+<p>
+ This processor serves as a counterpart for PutSplunk processor. While the later solves communication using TCP and
+ UDP protocols, PutSplunkHTTP aims to send events into Splunk via HTTP or HTTPS. In this fashion, this processor
+ shows similarities with GetSplunk processor and the properties relevant to the connection with Splunk server are
+ identical. There are however some aspects unique for this processor:
+</p>
+
+<h3>Content details</h3>
+
+<p>
+ PutSplunkHTTP allows the user to specify some metadata about the event is being sent to the Splunk. These include: the
Review comment:
typo: should be "some metadata about the event being sent" - reads "some metadata about the event _is_ being sent"
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.RESPONDED_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.RESPONDED_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(ackId.get(), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().debug("There was no eligible flow file to send request to Splunk.");
+ return;
+ }
+
+ try {
+ requestMessage = createRequestMessage(undetermined);
+ } catch (final IOException e) {
+ getLogger().error("Could not prepare Splunk request!", e);
+ session.transfer(undetermined.values(), RELATIONSHIP_FAILURE);
+ return;
+ }
+
+ try {
+ final ResponseMessage responseMessage = call(ENDPOINT, requestMessage);
+
+ if (responseMessage.getStatus() == 200) {
+ final EventIndexStatusResponse splunkResponse = unmarshallResult(responseMessage.getContent(), EventIndexStatusResponse.class);
+
+ splunkResponse.getAcks().entrySet().forEach(result -> {
+ final FlowFile toTransfer = undetermined.get(result.getKey());
+
+ if (result.getValue()) {
+ session.transfer(toTransfer, RELATIONSHIP_ACKNOWLEDGED);
+ } else {
+ session.penalize(toTransfer);
+ session.transfer(toTransfer, RELATIONSHIP_UNDETERMINED);
+ }
+ });
+ } else {
+ getLogger().error("Query index status was not successful because of ({}) {}", new Object[] {responseMessage.getStatus(), responseMessage.getContent()});
+ context.yield();
+ session.transfer(undetermined.values(), RELATIONSHIP_UNDETERMINED);
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk server!", e);
Review comment:
Would generally recommend against exclamation points in logs
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.QuerySplunkIndexingStatus/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>QuerySplunkIndexingStatus</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>QuerySplunkIndexingStatus</h2>
+
+<p>
+ This processor is responsible for polling Splunk server and determine if a Splunk event is acknowledged at the time of
+ execution. For more details about the HEC Index Acknowledgement please see
+ <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/Data/AboutHECIDXAck">this documentation.</a>
+</p>
+
+<h3>Prerequisites</h3>
+
+<p>
+ In order to work properly, the incoming flow files need to have the attributes "splunk.acknowledgement.id" and
+ "splunk.responded.at" filled properly. The flow file attribute "splunk.acknowledgement.id" should continue the "ackId"
+ contained by the response of the Splunk from the original put call. The flow file attribute "splunk.responded.at"
+ should contain the Unix Epoch the put call was answered by Splunk. It is suggested to use PutSplunkHTTP processor to execute
+ the put call and set these attributes.
+</p>
+
+<h3>Unacknowledged and undetermined cases</h3>
+
+<p>
+ Splunk serves information only about successful acknowledgement. In every other case it will return a false value. This
+ includes unsuccessful or ongoing indexing and unknown acknowledgement identifiers. In order to avoid infinite tries,
+ QuerySplunkIndexingStatus gives user the possibility to set a "Maximum waiting time". False results from Splunk within
+ the specified waiting time will be handled as "undetermined" and are transferred to the "undetermined" relationship.
+ Flow files outside of this time range will be transferred to the "unacknowledged" relationship next time the processor is
+ triggered. In order to determine if the indexing of a given event is within the waiting time, the Unix Epoch stored in
+ the attribute specified by "Splunk Sent At Attribute Name" will be used. Setting "Maximum waiting time" too low might
Review comment:
I don't see a "Splunk Sent At Attribute Name" anywhere. Was this removed? If so, should update the docs.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: {}", new Object[] {e.getMessage()}, e);
+ } finally {
+ session.transfer(flowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
Review comment:
Thanks for that clarification. Probably makes sense to put a comment to that effect in the code so that it's understood later, as well.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r564480541
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
Review comment:
You are right about the exclamation mark. However, the explanation is in the next sentence :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r545048848
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: {}", new Object[] {e.getMessage()}, e);
+ } finally {
+ session.transfer(flowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
Review comment:
This approach is from the PublishJMS originally, but I do review it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] tpalfy commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r556579330
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.HttpException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final String ACKNOWLEDGEMENT_ID_ATTRIBUTE = "splunk.acknowledgement.id";
+ static final String SENT_AT_ATTRIBUTE = "splunk.responded.at";
Review comment:
```suggestion
static final String RESPONDED_AT_ATTRIBUTE = "splunk.responded.at";
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] markap14 commented on pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
markap14 commented on pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#issuecomment-767805980
Thanks @simonbence, all looks good to me. +1 merged to main!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r564617844
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
Review comment:
Splunk responses with a boolean value for this query. The only case it returns with "true" value, is the _first_ call after the acknowledgement is done. (Given it's called soon enough and is not moved out from the internal buffers of Splunk) In every other case, including failed acknowledgement, early poll, unknown id and further polls on acknowledged items, it will return "false", without further details. Thus, the "false" response is perfectly valid.
In order to avoid hitting the external resource (Splunk) continuously, I do keep the "question" open (transfering to undetermined), until it's answered by the Splunk properly or times out, and penalise the FF. Assuming it is looped back to the processor, in a later time, it should be tried again.
Practically this means, we polled too early and we do not want to try again with the given id for a while. As the processor works with batches of acknowledgement requests this is not equal to decreasing the frequency of the triggering.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r545108357
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
Review comment:
It remained here from a previous iteration by mistake.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539459375
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
Review comment:
I did not want to diverge from the way it is used in GetSplunk. I see your point however and it makes sense. In this story I would not want to tackle this one, but it would make sense to change in both places later (or even more: just based on a quick glance, the shared logic in GetSplunk might be called from SplunkAPICall)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r565091750
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.RESPONDED_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.RESPONDED_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
Review comment:
https://issues.apache.org/jira/browse/NIFI-8176
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539578290
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
Review comment:
That sounds reasonable, refactoring PutSplunkHTTP and GetSplunk in a separate issue sounds good.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539449901
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final FlowFile incomingFlowFile = session.get();
Review comment:
I was thinking that @InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED) should prevent from this, but thanks
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] markap14 commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
markap14 commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r538411444
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
Review comment:
Should probably be URL Encoding the user-defined values.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
Review comment:
These should not be done in an @OnUnscheduled method because it can lead to a race condition that can result in values be `null`ed out while the Processor is still running. Instead, this should be done in a method that uses the `@OnStopped` annotation.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
Review comment:
The phrase "Sends events" makes me wonder what type of data is expected here. Are these JSON, logs, etc.? Does the data format matter, or is it sent as a bunch of bytes? Does NiFi parse these events in any way?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final FlowFile incomingFlowFile = session.get();
+ FlowFile outgoingFlowFile = incomingFlowFile;
+ boolean success = false;
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, incomingFlowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ outgoingFlowFile = session.putAttribute(outgoingFlowFile, "splunk_status_code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = extractResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ outgoingFlowFile = enrichFlowFile(session, outgoingFlowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ outgoingFlowFile = session.putAttribute(outgoingFlowFile, "splunk_response_code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: (" + successResponse.getCode() + ") " + successResponse.getText());
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ default:
+ final SendRawDataResponse response = extractResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: " + response.getText());
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: " + e.getMessage(), e);
+ } finally {
+ session.transfer(outgoingFlowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
+ return requestMessage;
+ }
+
+ private String extractTextMessageBody(final FlowFile flowFile, final ProcessSession session, final String charset) {
+ final StringWriter writer = new StringWriter();
+ session.read(flowFile, in -> IOUtils.copy(in, writer, Charset.forName(charset)));
Review comment:
Any processor that reads the entire contents of FlowFile into memory should use the `@SystemResourceConsideration` annotation documenting that Memory is an important Resource Consideration because the entire FlowFile is loaded into memory.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+ final Map<Integer, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final String insertedAt = flowFile.getAttribute(insertedAtAttributeName);
+ final String ackId = flowFile.getAttribute(ackIdAttributeName);
+
+ if (ackId == null || insertedAt == null) {
+ getLogger().error("Flow file attributes \"" + insertedAtAttributeName + "\" and \"" + ackIdAttributeName + "\" are needed!");
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (Long.valueOf(insertedAt) + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(Integer.valueOf(flowFile.getAttribute(ackIdAttributeName)), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().info("There was no eligible flow file to send request to Splunk.");
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(undetermined);
+
+ final ResponseMessage responseMessage = call(ENDPOINT, requestMessage);
+
+ if (responseMessage.getStatus() == 200) {
+ final EventIndexStatusResponse splunkResponse = extractResult(responseMessage.getContent(), EventIndexStatusResponse.class);
+
+ splunkResponse.getAcks().entrySet().stream().forEach(result -> {
+ if (result.getValue()) {
+ session.transfer(undetermined.get(result.getKey()), RELATIONSHIP_ACKNOWLEDGED);
+ } else {
+ session.penalize(undetermined.get(result.getKey()));
+ session.transfer(undetermined.get(result.getKey()), RELATIONSHIP_UNDETERMINED);
+ }
+ });
+ } else {
+ getLogger().error("Query index status was not successful because of (" + responseMessage.getStatus() + ") " + responseMessage.getContent());
+ context.yield();
+ session.transfer(undetermined.values(), RELATIONSHIP_UNDETERMINED);
+ }
+ } catch (final IOException e) {
+ throw new ProcessException(e);
+ }
+ }
+
+ private RequestMessage createRequestMessage(Map<Integer, FlowFile> undetermined) throws JsonProcessingException {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ requestMessage.getHeader().put("Content-Type", "application/json");
+ requestMessage.setContent(generateContent(undetermined));
+ return requestMessage;
+ }
+
+ private String generateContent(final Map<Integer, FlowFile> undetermined) throws JsonProcessingException {
+ final EventIndexStatusRequest splunkRequest = new EventIndexStatusRequest();
+ splunkRequest.setAcks(undetermined.keySet().stream().collect(Collectors.toList()));
Review comment:
Should probably use `splunkRequest.setAcks(new ArrayList<>(undetermined.keySet()));` - the call to `.stream()` is quite expensive.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+ final Map<Integer, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final String insertedAt = flowFile.getAttribute(insertedAtAttributeName);
+ final String ackId = flowFile.getAttribute(ackIdAttributeName);
+
+ if (ackId == null || insertedAt == null) {
+ getLogger().error("Flow file attributes \"" + insertedAtAttributeName + "\" and \"" + ackIdAttributeName + "\" are needed!");
Review comment:
Should indicate the FlowFile in the error message, and should use `{}` rather than concatenating strings.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+ final Map<Integer, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final String insertedAt = flowFile.getAttribute(insertedAtAttributeName);
+ final String ackId = flowFile.getAttribute(ackIdAttributeName);
+
+ if (ackId == null || insertedAt == null) {
+ getLogger().error("Flow file attributes \"" + insertedAtAttributeName + "\" and \"" + ackIdAttributeName + "\" are needed!");
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (Long.valueOf(insertedAt) + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(Integer.valueOf(flowFile.getAttribute(ackIdAttributeName)), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().info("There was no eligible flow file to send request to Splunk.");
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(undetermined);
+
+ final ResponseMessage responseMessage = call(ENDPOINT, requestMessage);
+
+ if (responseMessage.getStatus() == 200) {
+ final EventIndexStatusResponse splunkResponse = extractResult(responseMessage.getContent(), EventIndexStatusResponse.class);
+
+ splunkResponse.getAcks().entrySet().stream().forEach(result -> {
Review comment:
Can avoid the call to `stream()` and just use `...entrySet().forEach(result -> {`. Changing to a Stream doesn't buy us anything here but is expensive.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final FlowFile incomingFlowFile = session.get();
+ FlowFile outgoingFlowFile = incomingFlowFile;
+ boolean success = false;
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, incomingFlowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ outgoingFlowFile = session.putAttribute(outgoingFlowFile, "splunk_status_code", String.valueOf(responseMessage.getStatus()));
Review comment:
Best to stick with the dotted-name convention (splunk.status.code) as that's the most common for nifi attribute (mime.type, for example). Also, should add a @WritesAttribute annotation documenting that this attribute is added.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final FlowFile incomingFlowFile = session.get();
+ FlowFile outgoingFlowFile = incomingFlowFile;
+ boolean success = false;
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, incomingFlowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ outgoingFlowFile = session.putAttribute(outgoingFlowFile, "splunk_status_code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = extractResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ outgoingFlowFile = enrichFlowFile(session, outgoingFlowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ outgoingFlowFile = session.putAttribute(outgoingFlowFile, "splunk_response_code", String.valueOf(successResponse.getCode()));
Review comment:
Again with try to avoid sticking to the typical convention of splunk.response.code
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final FlowFile incomingFlowFile = session.get();
+ FlowFile outgoingFlowFile = incomingFlowFile;
Review comment:
Is there a reason for declaring an incomingFlowFile, and then an outgoingFlowFile? It appears that the two represent the same FlowFile. So the more typical pattern would be to simply use `flowFile` as a variable:
```
FlowFile flowFile = session.get();
if (flowFIle == null) {
return;
}
```
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
Review comment:
Best to keep consistent Title Case for property names (i.e., Maximum Waiting Time)
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final FlowFile incomingFlowFile = session.get();
+ FlowFile outgoingFlowFile = incomingFlowFile;
+ boolean success = false;
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, incomingFlowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ outgoingFlowFile = session.putAttribute(outgoingFlowFile, "splunk_status_code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = extractResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ outgoingFlowFile = enrichFlowFile(session, outgoingFlowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ outgoingFlowFile = session.putAttribute(outgoingFlowFile, "splunk_response_code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: (" + successResponse.getCode() + ") " + successResponse.getText());
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
Review comment:
I assume that it is intentional that there is no `break` here and you intend for the code to fall-through? If so, can you add a simple 1-line comment indicating that the fall-through is intentional? Otherwise, it looks suspiciously like a bug.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ if (queryParameters.isEmpty()) {
+ endpoint = ENDPOINT;
+ } else {
+ endpoint = ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&"));
+ }
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final FlowFile incomingFlowFile = session.get();
Review comment:
Need to check for `null` and return if so.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
Review comment:
Under what conditions might they be penalized?
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
Review comment:
It is suggested not to set it too low. Is there any trade-off? Many users will see this and decided to set it to `999999999` as there's no indication that a higher value may result in any concern.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
Review comment:
Should check if `flowFiles.isEmpty()` and if so return immediately to avoid any necessary processing. Would even more the call to `System.currentTimeMillis();` after checking that, as there's no need to make a system call if we're not going to use the result.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
Review comment:
Again, needs @OnStopped annotation, not @OnUnscheduled
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.PutSplunkHTTP/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>PutSplunkHTTP</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>PutSplunkHTTP</h2>
+
+<p>
+ This processor serves as a counterpart for PutSplunk processor. While the later solves communication using TCP and
+ UDP protocols, PutSplunkHTTP aims to send events into Splunk via HTTP or HTTPS. In this fashion, this processor
+ shows similarities with GetSplunk processor and the properties relevant to the connection with Splunk server are
+ identical. There are however some aspects unique for this processor:
+</p>
+
+<h3>Content details</h3>
+
+<p>
+ PutSplunkHTTP allows the user to specify some metadata about the event is being sent to the Splunk. These include: the
+ "Character Type" and the "Content Type" of the flow file content, using the matching properties. If the incoming
Review comment:
I think that should read the Character Set, rather than Character Type
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+ final Map<Integer, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final String insertedAt = flowFile.getAttribute(insertedAtAttributeName);
+ final String ackId = flowFile.getAttribute(ackIdAttributeName);
+
+ if (ackId == null || insertedAt == null) {
+ getLogger().error("Flow file attributes \"" + insertedAtAttributeName + "\" and \"" + ackIdAttributeName + "\" are needed!");
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (Long.valueOf(insertedAt) + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(Integer.valueOf(flowFile.getAttribute(ackIdAttributeName)), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().info("There was no eligible flow file to send request to Splunk.");
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(undetermined);
+
+ final ResponseMessage responseMessage = call(ENDPOINT, requestMessage);
+
+ if (responseMessage.getStatus() == 200) {
+ final EventIndexStatusResponse splunkResponse = extractResult(responseMessage.getContent(), EventIndexStatusResponse.class);
+
+ splunkResponse.getAcks().entrySet().stream().forEach(result -> {
+ if (result.getValue()) {
+ session.transfer(undetermined.get(result.getKey()), RELATIONSHIP_ACKNOWLEDGED);
Review comment:
Several calls to `undetermined.get(result.getKey())` here. Probably best to just extract that out:
```
FlowFile toTransfer = undetermined.get(result.getKey());
```
and then reference that variable.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.PutSplunkHTTP/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>PutSplunkHTTP</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>PutSplunkHTTP</h2>
+
+<p>
+ This processor serves as a counterpart for PutSplunk processor. While the later solves communication using TCP and
+ UDP protocols, PutSplunkHTTP aims to send events into Splunk via HTTP or HTTPS. In this fashion, this processor
+ shows similarities with GetSplunk processor and the properties relevant to the connection with Splunk server are
+ identical. There are however some aspects unique for this processor:
+</p>
+
+<h3>Content details</h3>
+
+<p>
+ PutSplunkHTTP allows the user to specify some metadata about the event is being sent to the Splunk. These include: the
+ "Character Type" and the "Content Type" of the flow file content, using the matching properties. If the incoming
+ flow file has "mime.type" attribute, the processor will use it, expect the "Content Type" property is set, in which
Review comment:
"expect" here i think should have been "unless"
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+ final Map<Integer, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final String insertedAt = flowFile.getAttribute(insertedAtAttributeName);
+ final String ackId = flowFile.getAttribute(ackIdAttributeName);
+
+ if (ackId == null || insertedAt == null) {
+ getLogger().error("Flow file attributes \"" + insertedAtAttributeName + "\" and \"" + ackIdAttributeName + "\" are needed!");
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (Long.valueOf(insertedAt) + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(Integer.valueOf(flowFile.getAttribute(ackIdAttributeName)), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().info("There was no eligible flow file to send request to Splunk.");
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(undetermined);
+
+ final ResponseMessage responseMessage = call(ENDPOINT, requestMessage);
+
+ if (responseMessage.getStatus() == 200) {
+ final EventIndexStatusResponse splunkResponse = extractResult(responseMessage.getContent(), EventIndexStatusResponse.class);
+
+ splunkResponse.getAcks().entrySet().stream().forEach(result -> {
+ if (result.getValue()) {
+ session.transfer(undetermined.get(result.getKey()), RELATIONSHIP_ACKNOWLEDGED);
+ } else {
+ session.penalize(undetermined.get(result.getKey()));
+ session.transfer(undetermined.get(result.getKey()), RELATIONSHIP_UNDETERMINED);
+ }
+ });
+ } else {
+ getLogger().error("Query index status was not successful because of (" + responseMessage.getStatus() + ") " + responseMessage.getContent());
+ context.yield();
+ session.transfer(undetermined.values(), RELATIONSHIP_UNDETERMINED);
+ }
+ } catch (final IOException e) {
+ throw new ProcessException(e);
Review comment:
Rather than throw a ProcessException here, we should transfer the FlowFiles to failure. If there's a timeout or Splunk is unreachable, we don't necessarily want to just backlog the data indefinitely but rather give the user to choice so that they can retry X number of times, etc.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
Review comment:
Need to avoid null-ing out values in @OnUnscheduled. Use @OnStopped instead.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+ final Map<Integer, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final String insertedAt = flowFile.getAttribute(insertedAtAttributeName);
+ final String ackId = flowFile.getAttribute(ackIdAttributeName);
+
+ if (ackId == null || insertedAt == null) {
+ getLogger().error("Flow file attributes \"" + insertedAtAttributeName + "\" and \"" + ackIdAttributeName + "\" are needed!");
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (Long.valueOf(insertedAt) + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(Integer.valueOf(flowFile.getAttribute(ackIdAttributeName)), flowFile);
+ }
+ }
+
+ if (undetermined.isEmpty()) {
+ getLogger().info("There was no eligible flow file to send request to Splunk.");
Review comment:
Probably best to make that a debug-level log message
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
Review comment:
Should use `splunk.ackknowledgment.id`. To be honest, I would actually remove this property all together and use a well-known attribute name. I can't think of a scenario where the user would really need to change the value, and adding to the number of properties only makes things more confusing.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
Review comment:
Should probably add a `@SeeAlso` annotation pointing to the PutSplunkHTTP processor
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
Review comment:
Again, same comments as above. Should use splunk.send.at or even splunk.send.timestamp. But really doesn't need to be a Property - just use a well-known attribute that both processors understand.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred into this relationship when the acknowledgement state is not determined. " +
+ "Flow files transferred into this relationship might be penalized!")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("A FlowFile is transferred into this relationship when the acknowledgement was not successful.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum waiting time")
+ .description(
+ "The maximum time the service tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the service considers the index as not acknowledged and moves it into the output buffer as failed acknowledgement.")
+ .defaultValue("100 secs")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the service query status for in one batch. " +
+ "It is suggested to not set it too low in order to reduce network communication.")
+ .defaultValue("100")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final long currentTime = System.currentTimeMillis();
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+ final Map<Integer, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final String insertedAt = flowFile.getAttribute(insertedAtAttributeName);
+ final String ackId = flowFile.getAttribute(ackIdAttributeName);
+
+ if (ackId == null || insertedAt == null) {
+ getLogger().error("Flow file attributes \"" + insertedAtAttributeName + "\" and \"" + ackIdAttributeName + "\" are needed!");
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (Long.valueOf(insertedAt) + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
+ } else {
+ undetermined.put(Integer.valueOf(flowFile.getAttribute(ackIdAttributeName)), flowFile);
Review comment:
Should just use `ackId` rather than `flowFile.getAttribute()` again. Also should consider that if the attribute is not an integer, it will result in a rather unclear error message. Same as the `insertedAt` above. Might make sense to check that and provide a clean error message, such as "The 'splunk.inserted.at' attribute is expected to be an integer value but was <xyz>"
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends events to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+public class PutSplunkHTTP extends SplunkAPICall {
Review comment:
Should probably add a `@SeeAlso` annotation pointing to QuerySplunkIndexingStatus.class
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
Review comment:
Member variables should be private. If needed in subclasses, they should be exposed through protected methods.
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.PutSplunkHTTP/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>PutSplunkHTTP</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>PutSplunkHTTP</h2>
+
+<p>
+ This processor serves as a counterpart for PutSplunk processor. While the later solves communication using TCP and
+ UDP protocols, PutSplunkHTTP aims to send events into Splunk via HTTP or HTTPS. In this fashion, this processor
+ shows similarities with GetSplunk processor and the properties relevant to the connection with Splunk server are
+ identical. There are however some aspects unique for this processor:
+</p>
+
+<h3>Content details</h3>
+
+<p>
+ PutSplunkHTTP allows the user to specify some metadata about the event is being sent to the Splunk. These include: the
+ "Character Type" and the "Content Type" of the flow file content, using the matching properties. If the incoming
+ flow file has "mime.type" attribute, the processor will use it, expect the "Content Type" property is set, in which
+ case the property will override the flow file attribute.
+</p>
+
+<h3>Event parameters</h3>
+
+<p>
+ The "Source", "Source Type", "Host" and "Index" properties are optional and will be set by Splunk if unspecified. If set,
+ the default values will be overwritten by user specified ones. For more details about the Splunk API, please visit
+ <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/RESTREF/RESTinput#services.2Fcollector.2Fraw">this documentation</a>.
+</p>
+
+<h3>Acknowledgements</h3>
+
+<p>
+ HTTP Event Collector (HEC) in Splunk provides the possibility of index acknowledgement, which can be used to monitor
+ the indexing status of the individual events. PutSplunkHTTP supports this feature by enriching the outgoing flow file
+ with the necessary information, making it possible for a later processor to poll the status based on. The necessary
+ information for this is stored within the flow file attributes, specified by the "Splunk Acknowledgement Id Attribute Name"
+ and "Splunk Sent At Attribute Name".
+</p>
+
+<p>
+ For further steps of acknowledgement handling in NiFi side, please refer to QuerySplunkIndexingStatus processor. For more
+ details about the index acknowledgement, please visit <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/Data/AboutHECIDXAck">this documentation</a>.
+</p>
+
+<h3>Error information</h3>
+
+<p>
+ For more refined processing, flow files are extended with additional information if possible. The information is stored
Review comment:
I think 'enriched' is probably the right word here, rather than 'extended'. Or even 'updated'.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r545150841
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: {}", new Object[] {e.getMessage()}, e);
+ } finally {
+ session.transfer(flowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
Review comment:
Okay, I double checked this and the reason was to pick the same path as PublishJMS is the lack of support for OutputStream within Splunk's Service class. That is correct that setContent has a method for OutputStream, but when Service sends the request (com.splunk.HttpService.send) it directly casts content into String, which causes ClassCastException.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r564491889
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.RESPONDED_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.RESPONDED_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
Review comment:
There is a risk for that, given it is sitting enough time in the queue, but there must be an upper limit: Splunk has no explicit "unacknowledged" answer, thus it will return with a false value for cases where it is timed out in Splunk as well (or non-existing, or troubled ones or for ones with a previous positive answer. The default value of the TTL is 1 hour, which I believe should be enough for most healthy environment.
I could imagine an attribute on the flow file (something like a counter for attempts or even just a flag) would help. Are you okay with adding this in a follow up ticket?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539579281
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
Review comment:
That makes sense, both GetSplunk and PutSplunk use separate properties as implemented in PutSplunkHTTP, so staying with that convention here sounds good.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] markap14 commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
markap14 commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r564800231
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/QuerySplunkIndexingStatus.java
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.ReadsAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.EventIndexStatusRequest;
+import org.apache.nifi.dto.splunk.EventIndexStatusResponse;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http", "acknowledgement"})
+@CapabilityDescription("Queries Splunk server in order to acquire the status of indexing acknowledgement.")
+@ReadsAttributes({
+ @ReadsAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @ReadsAttribute(attribute = "splunk.responded.at", description = "The time of the response of put request for Splunk.")})
+@SeeAlso(PutSplunkHTTP.class)
+public class QuerySplunkIndexingStatus extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/ack";
+
+ static final Relationship RELATIONSHIP_ACKNOWLEDGED = new Relationship.Builder()
+ .name("success")
+ .description("A FlowFile is transferred to this relationship when the acknowledgement was successful.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNACKNOWLEDGED = new Relationship.Builder()
+ .name("unacknowledged")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful." +
+ "This can happen when the acknowledgement did not happened within the time period set for Maximum Waiting Time. " +
+ "FlowFiles with acknowledgement id unknown for the Splunk server will be transferred to this relationship after the Maximum Waiting Time is reached.")
+ .build();
+
+ static final Relationship RELATIONSHIP_UNDETERMINED = new Relationship.Builder()
+ .name("undetermined")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement state is not determined. " +
+ "FlowFiles transferred to this relationship might be penalized! " +
+ "This happens when Splunk returns with HTTP 200 but with false response for the acknowledgement id in the flow file attribute.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description(
+ "A FlowFile is transferred to this relationship when the acknowledgement was not successful due to errors during the communication. " +
+ "FlowFiles are timing out or unknown by the Splunk server will transferred to \"undetermined\" relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_ACKNOWLEDGED,
+ RELATIONSHIP_UNACKNOWLEDGED,
+ RELATIONSHIP_UNDETERMINED,
+ RELATIONSHIP_FAILURE
+ )));
+
+ static final PropertyDescriptor TTL = new PropertyDescriptor.Builder()
+ .name("ttl")
+ .displayName("Maximum Waiting Time")
+ .description(
+ "The maximum time the processor tries to acquire acknowledgement confirmation for an index, from the point of registration. " +
+ "After the given amount of time, the processor considers the index as not acknowledged and transfers the FlowFile to the \"unacknowledged\" relationship.")
+ .defaultValue("1 hour")
+ .required(true)
+ .addValidator(StandardValidators.TIME_PERIOD_VALIDATOR)
+ .build();
+
+ static final PropertyDescriptor MAX_QUERY_SIZE = new PropertyDescriptor.Builder()
+ .name("max-query-size")
+ .displayName("Maximum Query Size")
+ .description(
+ "The maximum number of acknowledgement identifiers the outgoing query contains in one batch. " +
+ "It is recommended not to set it too low in order to reduce network communication.")
+ .defaultValue("10000")
+ .required(true)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+ .build();
+
+ private volatile Integer maxQuerySize;
+ private volatile Integer ttl;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>();
+ final List<PropertyDescriptor> common = super.getSupportedPropertyDescriptors();
+ result.addAll(common);
+ result.add(TTL);
+ result.add(MAX_QUERY_SIZE);
+ return result;
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ maxQuerySize = context.getProperty(MAX_QUERY_SIZE).asInteger();
+ ttl = context.getProperty(TTL).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ maxQuerySize = null;
+ ttl = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ final RequestMessage requestMessage;
+ final List<FlowFile> flowFiles = session.get(maxQuerySize);
+
+ if (flowFiles.isEmpty()) {
+ return;
+ }
+
+ final long currentTime = System.currentTimeMillis();
+ final Map<Long, FlowFile> undetermined = new HashMap<>();
+
+ for (final FlowFile flowFile : flowFiles) {
+ final Optional<Long> sentAt = extractLong(flowFile.getAttribute(SplunkAPICall.RESPONDED_AT_ATTRIBUTE));
+ final Optional<Long> ackId = extractLong(flowFile.getAttribute(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE));
+
+ if (!sentAt.isPresent() || !ackId.isPresent()) {
+ getLogger().error("Flow file ({}) attributes {} and {} are expected to be set using 64-bit integer values!",
+ new Object[]{flowFile.getId(), SplunkAPICall.RESPONDED_AT_ATTRIBUTE, SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE});
+ session.transfer(flowFile, RELATIONSHIP_FAILURE);
+ } else if (sentAt.get() + ttl < currentTime) {
+ session.transfer(flowFile, RELATIONSHIP_UNACKNOWLEDGED);
Review comment:
Yeah I was thinking along the same lines - adding some sort of flag to indicate that at least one attempt had been made. That can probably be done in a follow-on ticket, that's fine.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539455671
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.PutSplunkHTTP/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>PutSplunkHTTP</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>PutSplunkHTTP</h2>
+
+<p>
+ This processor serves as a counterpart for PutSplunk processor. While the later solves communication using TCP and
+ UDP protocols, PutSplunkHTTP aims to send events into Splunk via HTTP or HTTPS. In this fashion, this processor
+ shows similarities with GetSplunk processor and the properties relevant to the connection with Splunk server are
+ identical. There are however some aspects unique for this processor:
+</p>
+
+<h3>Content details</h3>
+
+<p>
+ PutSplunkHTTP allows the user to specify some metadata about the event is being sent to the Splunk. These include: the
+ "Character Type" and the "Content Type" of the flow file content, using the matching properties. If the incoming
+ flow file has "mime.type" attribute, the processor will use it, expect the "Content Type" property is set, in which
+ case the property will override the flow file attribute.
+</p>
+
+<h3>Event parameters</h3>
+
+<p>
+ The "Source", "Source Type", "Host" and "Index" properties are optional and will be set by Splunk if unspecified. If set,
+ the default values will be overwritten by user specified ones. For more details about the Splunk API, please visit
+ <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/RESTREF/RESTinput#services.2Fcollector.2Fraw">this documentation</a>.
+</p>
+
+<h3>Acknowledgements</h3>
+
+<p>
+ HTTP Event Collector (HEC) in Splunk provides the possibility of index acknowledgement, which can be used to monitor
+ the indexing status of the individual events. PutSplunkHTTP supports this feature by enriching the outgoing flow file
+ with the necessary information, making it possible for a later processor to poll the status based on. The necessary
+ information for this is stored within the flow file attributes, specified by the "Splunk Acknowledgement Id Attribute Name"
+ and "Splunk Sent At Attribute Name".
+</p>
+
+<p>
+ For further steps of acknowledgement handling in NiFi side, please refer to QuerySplunkIndexingStatus processor. For more
+ details about the index acknowledgement, please visit <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/Data/AboutHECIDXAck">this documentation</a>.
+</p>
+
+<h3>Error information</h3>
+
+<p>
+ For more refined processing, flow files are extended with additional information if possible. The information is stored
Review comment:
Enriched was the word I wanted to use, not sure why I changed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] exceptionfactory commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539577611
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
Review comment:
Thanks for the background. I see how GetSplunk follows the same pattern, whereas PutSplunk uses the SSLContextService, but doesn't use the Splunk libraries. With that background, it sounds like a separate issue to refactor both PutSplunkHTTP and GetSplunk would be a reasonable way forward.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r544986364
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.HttpException;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
Review comment:
This is in order to have the same values as in GetSplunk.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r539468131
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/SplunkAPICall.java
##########
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import com.splunk.SSLSecurityProtocol;
+import com.splunk.Service;
+import com.splunk.ServiceArgs;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+
+abstract class SplunkAPICall extends AbstractProcessor {
+ private static final String REQUEST_CHANNEL_HEADER_NAME = "X-Splunk-Request-Channel";
+
+ private static final String HTTP_SCHEME = "http";
+ private static final String HTTPS_SCHEME = "https";
+
+ private static final AllowableValue TLS_1_2_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_2.name(), SSLSecurityProtocol.TLSv1_2.name());
+ private static final AllowableValue TLS_1_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1_1.name(), SSLSecurityProtocol.TLSv1_1.name());
+ private static final AllowableValue TLS_1_VALUE = new AllowableValue(SSLSecurityProtocol.TLSv1.name(), SSLSecurityProtocol.TLSv1.name());
+ private static final AllowableValue SSL_3_VALUE = new AllowableValue(SSLSecurityProtocol.SSLv3.name(), SSLSecurityProtocol.SSLv3.name());
+
+ static final PropertyDescriptor SCHEME = new PropertyDescriptor.Builder()
+ .name("Scheme")
+ .description("The scheme for connecting to Splunk.")
+ .allowableValues(HTTPS_SCHEME, HTTP_SCHEME)
+ .defaultValue(HTTPS_SCHEME)
+ .required(true)
+ .build();
+
+ static final PropertyDescriptor HOSTNAME = new PropertyDescriptor.Builder()
+ .name("Hostname")
+ .description("The ip address or hostname of the Splunk server.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .defaultValue("localhost")
+ .required(true)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PORT = new PropertyDescriptor
+ .Builder().name("Port")
+ .description("The HTTP Port Number of the Splunk server.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("9088")
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SECURITY_PROTOCOL = new PropertyDescriptor.Builder()
+ .name("Security Protocol")
+ .description("The security protocol to use for communicating with Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .allowableValues(TLS_1_2_VALUE, TLS_1_1_VALUE, TLS_1_VALUE, SSL_3_VALUE)
+ .defaultValue(TLS_1_2_VALUE.getValue())
+ .build();
+
+ static final PropertyDescriptor OWNER = new PropertyDescriptor.Builder()
+ .name("Owner")
+ .description("The owner to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor TOKEN = new PropertyDescriptor.Builder()
+ .name("Token")
+ .description("The token to pass to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("Username")
+ .description("The username to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("Password")
+ .description("The password to authenticate to Splunk.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .required(false)
+ .sensitive(true)
+ .build();
+
+ static final PropertyDescriptor REQUEST_CHANNEL = new PropertyDescriptor.Builder()
+ .name("request-channel")
+ .displayName("Splunk Request Channel")
+ .description("Identifier of the used request channel.")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_ACK_ID_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-ack-id-attribute-name")
+ .displayName("Splunk Acknowledgement Id Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the Splunk acknowledgement id.")
+ .defaultValue("splunk_acknowledgement_id")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SPLUNK_SENT_AT_ATTRIBUTE = new PropertyDescriptor.Builder()
+ .name("splunk-sent-at-attribute")
+ .displayName("Splunk Sent At Attribute Name")
+ .description("Specifies which flow file attribute will be used to store the time of sending the event into Splunk.")
+ .defaultValue("splunk_send_at")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ protected static final List<PropertyDescriptor> PROPERTIES = Arrays.asList(
+ SCHEME,
+ HOSTNAME,
+ PORT,
+ SECURITY_PROTOCOL,
+ OWNER,
+ TOKEN,
+ USERNAME,
+ PASSWORD,
+ REQUEST_CHANNEL,
+ SPLUNK_ACK_ID_ATTRIBUTE,
+ SPLUNK_SENT_AT_ATTRIBUTE
+ );
+
+ protected final JsonFactory jsonFactory = new JsonFactory();
+ protected final ObjectMapper jsonObjectMapper = new ObjectMapper(jsonFactory);
+
+ protected volatile ServiceArgs splunkServiceArguments;
+ protected volatile Service splunkService;
+ protected volatile String requestChannel;
+ protected volatile String ackIdAttributeName;
+ protected volatile String insertedAtAttributeName;
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return SplunkAPICall.PROPERTIES;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ splunkServiceArguments = getSplunkServiceArgs(context);
+ splunkService = getSplunkService(splunkServiceArguments);
+ requestChannel = context.getProperty(SplunkAPICall.REQUEST_CHANNEL).evaluateAttributeExpressions().getValue();
+ ackIdAttributeName = context.getProperty(SplunkAPICall.SPLUNK_ACK_ID_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ insertedAtAttributeName = context.getProperty(SplunkAPICall.SPLUNK_SENT_AT_ATTRIBUTE).evaluateAttributeExpressions().getValue();
+ }
+
+ private ServiceArgs getSplunkServiceArgs(final ProcessContext context) {
+ final ServiceArgs splunkServiceArguments = new ServiceArgs();
+
+ splunkServiceArguments.setScheme(context.getProperty(SCHEME).getValue());
+ splunkServiceArguments.setHost(context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
+ splunkServiceArguments.setPort(context.getProperty(PORT).evaluateAttributeExpressions().asInteger());
+
+ if (context.getProperty(OWNER).isSet()) {
+ splunkServiceArguments.setOwner(context.getProperty(OWNER).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(TOKEN).isSet()) {
+ splunkServiceArguments.setToken(context.getProperty(TOKEN).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(USERNAME).isSet()) {
+ splunkServiceArguments.setUsername(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(PASSWORD).isSet()) {
+ splunkServiceArguments.setPassword(context.getProperty(PASSWORD).getValue());
+ }
+
+ if (HTTPS_SCHEME.equals(context.getProperty(SCHEME).getValue()) && context.getProperty(SECURITY_PROTOCOL).isSet()) {
+ splunkServiceArguments.setSSLSecurityProtocol(SSLSecurityProtocol.valueOf(context.getProperty(SECURITY_PROTOCOL).getValue()));
+ }
+
+ return splunkServiceArguments;
+ }
+
+ protected Service getSplunkService(final ServiceArgs splunkServiceArguments) {
+ return Service.connect(splunkServiceArguments);
+ }
+
+ @OnUnscheduled
+ public void onUnscheduled() {
+ if (splunkService != null) {
+ splunkService.logout();
+ splunkService = null;
+ }
+
+ requestChannel = null;
+ ackIdAttributeName = null;
+ insertedAtAttributeName = null;
+ splunkServiceArguments = null;
+ }
+
+ protected ResponseMessage call(final String endpoint, final RequestMessage request) {
+ request.getHeader().put(REQUEST_CHANNEL_HEADER_NAME, requestChannel);
+
+ try {
+ return splunkService.send(endpoint, request);
+ //Catch Stale connection exception, reinitialize, and retry
+ } catch (final com.splunk.HttpException e) {
+ getLogger().error("Splunk request status code:" + e.getStatus() + " Retrying the request.");
+ splunkService.logout();
+ splunkService = getSplunkService(splunkServiceArguments);
+ return splunkService.send(endpoint, request);
+ }
+ }
+
+ protected <T> T extractResult(final InputStream responseBody, final Class<T> type) throws IOException {
+ final JsonParser jsonParser = jsonFactory.createParser(responseBody);
+ jsonParser.setCodec(jsonObjectMapper);
+ return jsonParser.readValueAs(type);
Review comment:
Nice improvement, I was not aware of this
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r564631086
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/resources/docs/org.apache.nifi.processors.splunk.QuerySplunkIndexingStatus/additionalDetails.html
##########
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html lang="en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<head>
+ <meta charset="utf-8" />
+ <title>QuerySplunkIndexingStatus</title>
+ <link rel="stylesheet" href="/nifi-docs/css/component-usage.css" type="text/css" />
+</head>
+
+<body>
+<h2>QuerySplunkIndexingStatus</h2>
+
+<p>
+ This processor is responsible for polling Splunk server and determine if a Splunk event is acknowledged at the time of
+ execution. For more details about the HEC Index Acknowledgement please see
+ <a href="https://docs.splunk.com/Documentation/Splunk/LATEST/Data/AboutHECIDXAck">this documentation.</a>
+</p>
+
+<h3>Prerequisites</h3>
+
+<p>
+ In order to work properly, the incoming flow files need to have the attributes "splunk.acknowledgement.id" and
+ "splunk.responded.at" filled properly. The flow file attribute "splunk.acknowledgement.id" should continue the "ackId"
+ contained by the response of the Splunk from the original put call. The flow file attribute "splunk.responded.at"
+ should contain the Unix Epoch the put call was answered by Splunk. It is suggested to use PutSplunkHTTP processor to execute
+ the put call and set these attributes.
+</p>
+
+<h3>Unacknowledged and undetermined cases</h3>
+
+<p>
+ Splunk serves information only about successful acknowledgement. In every other case it will return a false value. This
+ includes unsuccessful or ongoing indexing and unknown acknowledgement identifiers. In order to avoid infinite tries,
+ QuerySplunkIndexingStatus gives user the possibility to set a "Maximum waiting time". False results from Splunk within
+ the specified waiting time will be handled as "undetermined" and are transferred to the "undetermined" relationship.
+ Flow files outside of this time range will be transferred to the "unacknowledged" relationship next time the processor is
+ triggered. In order to determine if the indexing of a given event is within the waiting time, the Unix Epoch stored in
+ the attribute specified by "Splunk Sent At Attribute Name" will be used. Setting "Maximum waiting time" too low might
Review comment:
You are correct, this remained here by mistake. Originally the name of this attribute was configurable but during review it was simplified.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi] simonbence commented on a change in pull request #4714: NIFI-7801 Adding support for HTTP based Splunk put and indexed acknowledgement
Posted by GitBox <gi...@apache.org>.
simonbence commented on a change in pull request #4714:
URL: https://github.com/apache/nifi/pull/4714#discussion_r544994250
##########
File path: nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.splunk;
+
+import com.splunk.RequestMessage;
+import com.splunk.ResponseMessage;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.ReadsAttribute;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.dto.splunk.SendRawDataResponse;
+import org.apache.nifi.dto.splunk.SendRawDataSuccessResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@Tags({"splunk", "logs", "http"})
+@CapabilityDescription("Sends flow file content to the specified Splunk server over HTTP or HTTPS. Supports HEC Index Acknowledgement.")
+@ReadsAttribute(attribute = "mime.type", description = "Uses as value for HTTP Content-Type header if set.")
+@WritesAttributes({
+ @WritesAttribute(attribute = "splunk.acknowledgement.id", description = "The indexing acknowledgement id provided by Splunk."),
+ @WritesAttribute(attribute = "splunk.send.at", description = "The time of sending the put request for Splunk.")})
+@SystemResourceConsideration(resource = SystemResource.MEMORY)
+@SeeAlso(QuerySplunkIndexingStatus.class)
+public class PutSplunkHTTP extends SplunkAPICall {
+ private static final String ENDPOINT = "/services/collector/raw";
+
+ static final PropertyDescriptor SOURCE = new PropertyDescriptor.Builder()
+ .name("source")
+ .displayName("Source")
+ .description("User-defined event source. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor SOURCE_TYPE = new PropertyDescriptor.Builder()
+ .name("source-type")
+ .displayName("Source Type")
+ .description("User-defined event sourcetype. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
+ .name("host")
+ .displayName("Host")
+ .description("Specify with the host query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor INDEX = new PropertyDescriptor.Builder()
+ .name("index")
+ .displayName("Index")
+ .description("Index name. Specify with the index query string parameter. Sets a default for all events when unspecified.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("character-set")
+ .displayName("Character Set")
+ .description("The name of the character set.")
+ .required(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .defaultValue(Charset.defaultCharset().name())
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final PropertyDescriptor CONTENT_TYPE = new PropertyDescriptor.Builder()
+ .name("content-type")
+ .displayName("Content Type")
+ .description(
+ "The media type of the event sent to Splunk. " +
+ "If not set, \"mime.type\" flow file attribute will be used. " +
+ "In case of neither of them is specified, this information will not be sent to the server.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+
+ static final Relationship RELATIONSHIP_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("FlowFiles that are sent successfully to the destination are sent out this relationship.")
+ .build();
+
+ static final Relationship RELATIONSHIP_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("FlowFiles that failed to send to the destination are sent out this relationship.")
+ .build();
+
+ private static final Set<Relationship> RELATIONSHIPS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+ RELATIONSHIP_SUCCESS,
+ RELATIONSHIP_FAILURE)));
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return RELATIONSHIPS;
+ }
+
+ @Override
+ public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ final List<PropertyDescriptor> result = new ArrayList<>(super.getSupportedPropertyDescriptors());
+ result.add(SOURCE);
+ result.add(SOURCE_TYPE);
+ result.add(HOST);
+ result.add(INDEX);
+ result.add(CONTENT_TYPE);
+ result.add(CHARSET);
+ return result;
+ }
+
+ private volatile String endpoint;
+ private volatile String contentType;
+ private volatile String charset;
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+
+ if (context.getProperty(CONTENT_TYPE).isSet()) {
+ contentType = context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions().getValue();
+ }
+
+ charset = context.getProperty(CHARSET).evaluateAttributeExpressions().getValue();
+
+ final Map<String, String> queryParameters = new HashMap<>();
+
+ if (context.getProperty(SOURCE_TYPE).isSet()) {
+ queryParameters.put("sourcetype", context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(SOURCE).isSet()) {
+ queryParameters.put("source", context.getProperty(SOURCE).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(HOST).isSet()) {
+ queryParameters.put("host", context.getProperty(HOST).evaluateAttributeExpressions().getValue());
+ }
+
+ if (context.getProperty(INDEX).isSet()) {
+ queryParameters.put("index", context.getProperty(INDEX).evaluateAttributeExpressions().getValue());
+ }
+
+ endpoint = getEndpoint(queryParameters);
+ }
+
+ private String getEndpoint(final Map<String, String> queryParameters) {
+ if (queryParameters.isEmpty()) {
+ return ENDPOINT;
+ }
+
+ try {
+ return URLEncoder.encode(ENDPOINT + '?' + queryParameters.entrySet().stream().map(e -> e.getKey() + '=' + e.getValue()).collect(Collectors.joining("&")), "UTF-8");
+ } catch (final UnsupportedEncodingException e) {
+ getLogger().error("Could not be initialized because of: {}", new Object[] {e.getMessage()}, e);
+ throw new ProcessException(e);
+ }
+ }
+
+ @OnStopped
+ public void onUnscheduled() {
+ super.onUnscheduled();
+ contentType = null;
+ charset = null;
+ endpoint = null;
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ boolean success = false;
+
+ if (flowFile == null) {
+ return;
+ }
+
+ try {
+ final RequestMessage requestMessage = createRequestMessage(session, flowFile);
+ final ResponseMessage responseMessage = call(endpoint, requestMessage);
+ flowFile = session.putAttribute(flowFile, "splunk.status.code", String.valueOf(responseMessage.getStatus()));
+
+ switch (responseMessage.getStatus()) {
+ case 200:
+ final SendRawDataSuccessResponse successResponse = unmarshallResult(responseMessage.getContent(), SendRawDataSuccessResponse.class);
+
+ if (successResponse.getCode() == 0) {
+ flowFile = enrichFlowFile(session, flowFile, successResponse.getAckId());
+ success = true;
+ } else {
+ flowFile = session.putAttribute(flowFile, "splunk.response.code", String.valueOf(successResponse.getCode()));
+ getLogger().error("Putting data into Splunk was not successful: ({}) {}", new Object[] {successResponse.getCode(), successResponse.getText()});
+ }
+
+ break;
+ case 503 : // HEC is unhealthy, queues are full
+ context.yield();
+ // fall-through
+ default:
+ final SendRawDataResponse response = unmarshallResult(responseMessage.getContent(), SendRawDataResponse.class);
+ getLogger().error("Putting data into Splunk was not successful: {}", new Object[] {response.getText()});
+ }
+ } catch (final Exception e) {
+ getLogger().error("Error during communication with Splunk: {}", new Object[] {e.getMessage()}, e);
+ } finally {
+ session.transfer(flowFile, success ? RELATIONSHIP_SUCCESS : RELATIONSHIP_FAILURE);
+ }
+ }
+
+ private RequestMessage createRequestMessage(final ProcessSession session, final FlowFile flowFile) {
+ final RequestMessage requestMessage = new RequestMessage("POST");
+ final String flowFileContentType = Optional.ofNullable(contentType).orElse(flowFile.getAttribute("mime.type"));
+
+ if (flowFileContentType != null) {
+ requestMessage.getHeader().put("Content-Type", flowFileContentType);
+ }
+
+ requestMessage.setContent(extractTextMessageBody(flowFile, session, charset));
+ return requestMessage;
+ }
+
+ private String extractTextMessageBody(final FlowFile flowFile, final ProcessSession session, final String charset) {
+ final StringWriter writer = new StringWriter();
+ session.read(flowFile, in -> IOUtils.copy(in, writer, Charset.forName(charset)));
+ return writer.toString();
+ }
+
+ private FlowFile enrichFlowFile(final ProcessSession session, final FlowFile flowFile, final long ackId) {
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put(SplunkAPICall.ACKNOWLEDGEMENT_ID_ATTRIBUTE, String.valueOf(ackId));
+ attributes.put(SplunkAPICall.SENT_AT_ATTRIBUTE, String.valueOf(System.currentTimeMillis()));
Review comment:
The difference should not be important, but your observation is correct. With a healthy environment, Splunk should response quickly enough for the difference ending up with much lower scale than the timeout we use it for to compare. But yeah, this is a mixed bag here... let me think it over. I might change it on a way that it uses the time of send or rename the attribute.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org