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

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

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

    https://github.com/apache/nifi/pull/257#discussion_r55185061
  
    --- Diff: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/SNMPUtils.java
 ---
    @@ -0,0 +1,268 @@
    +/*
    + * 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.snmp.processors;
    +
    +import java.lang.reflect.Method;
    +import java.lang.reflect.Modifier;
    +import java.util.Arrays;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Vector;
    +import java.util.regex.Pattern;
    +
    +import org.apache.nifi.components.ValidationContext;
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.components.Validator;
    +import org.apache.nifi.flowfile.FlowFile;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.snmp4j.PDU;
    +import org.snmp4j.security.AuthMD5;
    +import org.snmp4j.security.AuthSHA;
    +import org.snmp4j.security.Priv3DES;
    +import org.snmp4j.security.PrivAES128;
    +import org.snmp4j.security.PrivAES192;
    +import org.snmp4j.security.PrivAES256;
    +import org.snmp4j.security.PrivDES;
    +import org.snmp4j.security.SecurityLevel;
    +import org.snmp4j.smi.OID;
    +import org.snmp4j.smi.VariableBinding;
    +import org.snmp4j.util.TreeEvent;
    +
    +/**
    + * Utility helper class that simplifies interactions with target SNMP API 
and NIFI API.
    + */
    +abstract class SNMPUtils {
    +
    +    /** logger */
    +    private final static Logger logger = 
LoggerFactory.getLogger(SNMPUtils.class);
    +
    +    /** OID Pattern */
    +    public final static Pattern OID_PATTERN = 
Pattern.compile("[[0-9]+\\.]*");
    +
    +    /** delimiter for properties name */
    +    public final static String SNMP_PROP_DELIMITER = "$";
    +
    +    /** prefix for SNMP properties in flow file */
    +    public final static String SNMP_PROP_PREFIX = "snmp" + 
SNMP_PROP_DELIMITER;
    +
    +    /** list of properties name when performing simple get */
    +    private final static List<String> propertyNames = 
Arrays.asList("snmp$errorIndex", "snmp$errorStatus", "snmp$errorStatusText",
    +            "snmp$nonRepeaters", "snmp$requestID", "snmp$type", 
"snmp$variableBindings");
    +
    +    /** used to validate OID syntax */
    +    public static final Validator SNMP_OID_VALIDATOR = new Validator() {
    +        @Override
    +        public ValidationResult validate(final String subject, final 
String input, final ValidationContext context) {
    +            final ValidationResult.Builder builder = new 
ValidationResult.Builder();
    +            builder.subject(subject).input(input);
    +            if (context.isExpressionLanguageSupported(subject) && 
context.isExpressionLanguagePresent(input)) {
    +                return builder.valid(true).explanation("Contains 
Expression Language").build();
    +            }
    +            try {
    +                if (OID_PATTERN.matcher(input).matches()) {
    +                    builder.valid(true);
    +                } else {
    +                    builder.valid(false).explanation(input + "is not a 
valid OID");
    +                }
    +            } catch (final IllegalArgumentException e) {
    +                builder.valid(false).explanation(e.getMessage());
    +            }
    +            return builder.build();
    +        }
    +    };
    +
    +    /**
    +     * Updates {@link FlowFile} with attributes representing PDU properties
    +     * @param response PDU retried from SNMP Agent
    +     * @param flowFile instance of target {@link FlowFile}
    +     * @param processSession instance of {@link ProcessSession}
    +     * @return updated {@link FlowFile}
    +     */
    +    public static FlowFile updateFlowFileAttributesWithPduProperties(PDU 
response, FlowFile flowFile, ProcessSession processSession) {
    +        if (response != null) {
    +            try {
    +                Method[] methods = PDU.class.getDeclaredMethods();
    +                Map<String, String> attributes = new HashMap<String, 
String>();
    +                for (Method method : methods) {
    +                    if (Modifier.isPublic(method.getModifiers()) && 
(method.getParameterCount() == 0) && method.getName().startsWith("get")) {
    --- End diff --
    
    Thanks Oleg, I have fixed it.


> Add SNMP processors
> -------------------
>
>                 Key: NIFI-1537
>                 URL: https://issues.apache.org/jira/browse/NIFI-1537
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: 0.5.0
>            Reporter: Pierre Villard
>            Assignee: Pierre Villard
>            Priority: Minor
>             Fix For: 0.6.0
>
>
> Add SNMP processors:
> - GetSNMP to allow "get"/"walk"
> - SetSNMP to allow "set"



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

Reply via email to