[GitHub] nifi issue #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on the issue: https://github.com/apache/nifi/pull/1108 @trixpan @joewitt Sorry for the long delay, I applied the changes that you suggested such as, adding the custom validator in the processor class, use the new version of grok and removing the license section from the assembly license --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi issue #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on the issue: https://github.com/apache/nifi/pull/1108 @trixpan @markap14 I pushed the new changes. Could you please check the changes ? Thanks! --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on a diff in the pull request: https://github.com/apache/nifi/pull/1108#discussion_r83729426 --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGrokParser.java --- @@ -0,0 +1,104 @@ +/* + * 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.standard; + + +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Created by snamsi on 05/10/16. + */ +public class TestGrokParser { + +private TestRunner testRunner; +final static Path GROK_LOG_INPUT = Paths.get("src/test/resources/TestGrokParser/apache.log"); +final static Path GROK_TEXT_INPUT = Paths.get("src/test/resources/TestGrokParser/simple_text.log"); + + +@Before +public void init() { +testRunner = TestRunners.newTestRunner(GrokParser.class); +} + +@Test +public void testGrokParserWithMatchedContent() throws IOException { + + +testRunner.setProperty(GrokParser.GROK_EXPRESSION, "%{COMMONAPACHELOG}"); +testRunner.setProperty(GrokParser.GROK_PATTERN_FILE, "src/test/resources/TestGrokParser/patterns"); +testRunner.enqueue(GROK_LOG_INPUT); +testRunner.run(); +testRunner.assertAllFlowFilesTransferred(GrokParser.REL_MATCH); +final MockFlowFile matched = testRunner.getFlowFilesForRelationship(GrokParser.REL_MATCH).get(0); + +matched.assertAttributeEquals("verb","GET"); +matched.assertAttributeEquals("response","401"); +matched.assertAttributeEquals("bytes","12846"); +matched.assertAttributeEquals("clientip","64.242.88.10"); +matched.assertAttributeEquals("auth","-"); +matched.assertAttributeEquals("timestamp","07/Mar/2004:16:05:49 -0800"); + matched.assertAttributeEquals("request","/twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables"); +matched.assertAttributeEquals("httpversion","1.1"); + +} + +@Test +public void testGrokParserWithUnMatchedContent() throws IOException { + + +testRunner.setProperty(GrokParser.GROK_EXPRESSION, "%{ADDRESS}"); +testRunner.setProperty(GrokParser.GROK_PATTERN_FILE, "src/test/resources/TestGrokParser/patterns"); +testRunner.enqueue(GROK_TEXT_INPUT); +testRunner.run(); +testRunner.assertAllFlowFilesTransferred(GrokParser.REL_NO_MATCH); +final MockFlowFile notMatched = testRunner.getFlowFilesForRelationship(GrokParser.REL_NO_MATCH).get(0); +notMatched.assertContentEquals(GROK_TEXT_INPUT); + +} + +@Test(expected = java.lang.AssertionError.class) +public void testGrokParserWithNotFoundPatternFile() throws IOException { + +testRunner.setProperty(GrokParser.GROK_EXPRESSION, "%{COMMONAPACHELOG}"); +testRunner.setProperty(GrokParser.GROK_PATTERN_FILE, "src/test/resources/TestGrokParser/toto_file"); +testRunner.enqueue(GROK_LOG_INPUT); +testRunner.run(); + +} + + +@Test(expected = java.lang.AssertionError.class) --- End diff -- For this method "testGrokParserWithBadGrokExpression", although the processor is throwing GrokException, when I use assertNotValid, the test fails with the following message "java.lang.AssertionError: Processor appears to be va
[GitHub] nifi issue #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on the issue: https://github.com/apache/nifi/pull/1108 @markap14 Thanks for all this suggestions, I'll update the code ASAP and push the changes! --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on a diff in the pull request: https://github.com/apache/nifi/pull/1108#discussion_r83720911 --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GrokParser.java --- @@ -0,0 +1,243 @@ +/* + * 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.standard; + +import com.fasterxml.jackson.databind.ObjectMapper; +import oi.thekraken.grok.api.Grok; +import oi.thekraken.grok.api.Match; +import oi.thekraken.grok.api.exception.GrokException; +import org.apache.nifi.annotation.behavior.ReadsAttribute; +import org.apache.nifi.annotation.behavior.ReadsAttributes; +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.components.PropertyDescriptor; +import org.apache.nifi.flowfile.attributes.CoreAttributes; +import org.apache.nifi.flowfile.FlowFile; + +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.DataUnit; +import org.apache.nifi.processor.ProcessorInitializationContext; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.StreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.stream.io.BufferedOutputStream; +import org.apache.nifi.stream.io.StreamUtils; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.Charset; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.util.HashSet; +import java.util.ArrayList; +import java.util.Collections; + + +@Tags({"Grok Processor"}) +@CapabilityDescription("Use Grok expression ,a la logstash, to parse data.") +@SeeAlso({}) +@ReadsAttributes({@ReadsAttribute(attribute="", description="")}) +@WritesAttributes({@WritesAttribute(attribute="", description="")}) +public class GrokParser extends AbstractProcessor { + + +public static final String DESTINATION_ATTRIBUTE = "flowfile-attribute"; +public static final String DESTINATION_CONTENT = "flowfile-content"; +private static final String APPLICATION_JSON = "application/json"; + +public static final PropertyDescriptor GROK_EXPRESSION = new PropertyDescriptor +.Builder().name("Grok Expression") +.description("Grok expression") +.required(true) +.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) +.build(); + +public static final PropertyDescriptor GROK_PATTERN_FILE = new PropertyDescriptor +.Builder().name("Grok Pattern file") +.description("Grok Pattern file definition") +.required(false) --- End diff -- @markap14 In the first version of the code, I was loading few useful pattern files by default, so the user's custom pattern file was not required, but after removing that part I forgot to update the required attribute, I'll fix it --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on a diff in the pull request: https://github.com/apache/nifi/pull/1108#discussion_r83720540 --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GrokParser.java --- @@ -0,0 +1,243 @@ +/* + * 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.standard; + +import com.fasterxml.jackson.databind.ObjectMapper; +import oi.thekraken.grok.api.Grok; +import oi.thekraken.grok.api.Match; +import oi.thekraken.grok.api.exception.GrokException; +import org.apache.nifi.annotation.behavior.ReadsAttribute; +import org.apache.nifi.annotation.behavior.ReadsAttributes; +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.components.PropertyDescriptor; +import org.apache.nifi.flowfile.attributes.CoreAttributes; +import org.apache.nifi.flowfile.FlowFile; + +import org.apache.nifi.processor.AbstractProcessor; +import org.apache.nifi.processor.DataUnit; +import org.apache.nifi.processor.ProcessorInitializationContext; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.io.InputStreamCallback; +import org.apache.nifi.processor.io.StreamCallback; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.stream.io.BufferedOutputStream; +import org.apache.nifi.stream.io.StreamUtils; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.Charset; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.util.HashSet; +import java.util.ArrayList; +import java.util.Collections; + + +@Tags({"Grok Processor"}) +@CapabilityDescription("Use Grok expression ,a la logstash, to parse data.") +@SeeAlso({}) +@ReadsAttributes({@ReadsAttribute(attribute="", description="")}) +@WritesAttributes({@WritesAttribute(attribute="", description="")}) +public class GrokParser extends AbstractProcessor { + + +public static final String DESTINATION_ATTRIBUTE = "flowfile-attribute"; +public static final String DESTINATION_CONTENT = "flowfile-content"; +private static final String APPLICATION_JSON = "application/json"; + +public static final PropertyDescriptor GROK_EXPRESSION = new PropertyDescriptor +.Builder().name("Grok Expression") +.description("Grok expression") +.required(true) +.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) +.build(); + +public static final PropertyDescriptor GROK_PATTERN_FILE = new PropertyDescriptor +.Builder().name("Grok Pattern file") +.description("Grok Pattern file definition") +.required(false) +.addValidator(StandardValidators.FILE_EXISTS_VALIDATOR) +.build(); + +public static final PropertyDescriptor DESTINATION = new PropertyDescriptor.Builder() +.name("Destination") +.description("Control if Grok output value is written as a new flowfile attribute " + --- End diff -- @markap14 Actually what I meant is that the output will contain many new flowfile a
[GitHub] nifi issue #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on the issue: https://github.com/apache/nifi/pull/1108 @trixpan I figured out how to rebase the pull request :) Cheers --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request #1108: NIFI-2565: add Grok parser
Github user selim-namsi closed the pull request at: https://github.com/apache/nifi/pull/1108 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi issue #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on the issue: https://github.com/apache/nifi/pull/1108 @trixpan could you please tell me how to rebase a PR ? I rebased my [branch](https://github.com/selim-namsi/nifi/commits/nifi-2565) but I didn't find how to rebase the PR. sorry for the inconvenience , this is my first PR. Cheers --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi issue #1108: NIFI-2565: add Grok parser
Github user selim-namsi commented on the issue: https://github.com/apache/nifi/pull/1108 @trixpan Thank you for all this useful feedback, I'll start working on these modifications. For the patterns, I hard coded the patterns because I was thinking about adding by default some useful patterns and also let the user add his custom pattern. What do you think about it ? Thanks --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] nifi pull request #1108: NIFI-2565: add Grok parser
GitHub user selim-namsi opened a pull request: https://github.com/apache/nifi/pull/1108 NIFI-2565: add Grok parser Thank you for submitting a contribution to Apache NiFi. 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- where 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 master)? - [ ] Is your initial contribution a single, squashed commit? ### 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? - [ ] 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 travis-ci for build issues and submit an update to your PR as soon as possible. You can merge this pull request into a Git repository by running: $ git pull https://github.com/selim-namsi/nifi nifi-2565 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/nifi/pull/1108.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1108 commit 447c65ec272fd72b8b55a015f36449e387400fe6 Author: Selim Namsi <selim.na...@gmail.com> Date: 2016-10-05T16:54:37Z nifi-2565: add Grok parser commit 1dffac47057c85c7aba2e0b2a8543eafc88e96be Author: Selim Namsi <selim.na...@gmail.com> Date: 2016-10-05T17:17:49Z nifi-2656: Update LICENSE after adding Grok Parser --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---