[ 
https://issues.apache.org/jira/browse/NIFI-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15572097#comment-15572097
 ] 

ASF GitHub Bot commented on NIFI-2565:
--------------------------------------

Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1108#discussion_r83229335
  
    --- 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)
    --- End diff --
    
    Rather than expected an AssertionError, we should avoid calling 
testRunner.run() and instead just use testRunner.assertNotValid()


> NiFi processor to parse logs using Grok patterns
> ------------------------------------------------
>
>                 Key: NIFI-2565
>                 URL: https://issues.apache.org/jira/browse/NIFI-2565
>             Project: Apache NiFi
>          Issue Type: Improvement
>            Reporter: Andre
>             Fix For: 1.1.0
>
>
> Following up on Ryan Ward to create a Grok capable parser
> https://mail-archives.apache.org/mod_mbox/nifi-dev/201606.mbox/%3CCADD=rnPa8nHkJbeM280=PTQ=wurtwhstm5u+7btoo9pcym2...@mail.gmail.com%3E



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to