exceptionfactory commented on a change in pull request #5088:
URL: https://github.com/apache/nifi/pull/5088#discussion_r636228806



##########
File path: nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/pom.xml
##########
@@ -52,6 +52,16 @@ language governing permissions and limitations under the 
License. -->
             <version>1.14.0-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>30.1.1-jre</version>
+        </dependency>

Review comment:
       Google Guava is a large dependency that has historically required 
frequent upgrades.  I didn't see many uses of it, and it looks like some 
`Preconditions` references could be replaced with `Objects.requireNotNull()`.  
It would be best to avoid this dependency if possible.

##########
File path: nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/pom.xml
##########
@@ -52,6 +52,16 @@ language governing permissions and limitations under the 
License. -->
             <version>1.14.0-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>30.1.1-jre</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.76</version>

Review comment:
       Is there a particular reason for using `fastjson` as opposed to Jackson? 
 Although fastjson is license under ASL 2.0, Jackson is more commonly used in 
other components.

##########
File path: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/ListenTrapSNMP.java
##########
@@ -0,0 +1,203 @@
+/*
+ * 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 org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+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.OnStopped;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSessionFactory;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+import org.apache.nifi.snmp.operations.SNMPTrapReceiverHandler;
+import org.apache.nifi.snmp.utils.SNMPUtils;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Receiving data from configured SNMP agent which, upon each invocation of
+ * {@link #onTrigger(ProcessContext, ProcessSessionFactory)} method, will 
construct a
+ * {@link FlowFile} containing in its properties the information retrieved.
+ * The output {@link FlowFile} won't have any content.
+ */
+@Tags({"snmp", "listen", "trap"})
+@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
+@CapabilityDescription("Receives information from SNMP Agent and outputs a 
FlowFile with information in attributes and without any content")
+@WritesAttribute(attribute = SNMPUtils.SNMP_PROP_PREFIX + "*", description = 
"Attributes retrieved from the SNMP response. It may include:"
+        + " snmp$errorIndex, snmp$errorStatus, snmp$errorStatusText, 
snmp$nonRepeaters, snmp$requestID, snmp$type, snmp$variableBindings")
+@RequiresInstanceClassLoading
+public class ListenTrapSNMP extends AbstractSessionFactoryProcessor {
+
+    private static final String DEFAULT_HOST = "127.0.0.1";
+    private static final String DEFAULT_PORT = "0";
+
+    // SNMP versions
+    public static final AllowableValue SNMP_V1 = new AllowableValue("SNMPv1", 
"v1", "SNMP version 1");
+    public static final AllowableValue SNMP_V2C = new 
AllowableValue("SNMPv2c", "v2c", "SNMP version 2c");
+    public static final AllowableValue SNMP_V3 = new AllowableValue("SNMPv3", 
"v3", "SNMP version 3 with improved security");
+
+    // SNMPv3 security levels
+    public static final AllowableValue NO_AUTH_NO_PRIV = new 
AllowableValue("noAuthNoPriv", "No authentication or encryption",
+            "No authentication or encryption.");
+    public static final AllowableValue AUTH_NO_PRIV = new 
AllowableValue("authNoPriv", "Authentication without encryption",
+            "Authentication without encryption.");
+    public static final AllowableValue AUTH_PRIV = new 
AllowableValue("authPriv", "Authentication and encryption",
+            "Authentication and encryption.");
+
+    public static final PropertyDescriptor SNMP_MANAGER_PORT = new 
PropertyDescriptor.Builder()
+            .name("snmp-manager-port")
+            .displayName("SNMP Manager Port")
+            .description("The port where the SNMP Manager listens to the 
incoming traps.")
+            .required(true)
+            .defaultValue("0")
+            .addValidator(StandardValidators.PORT_VALIDATOR)
+            .build();
+
+    public static final PropertyDescriptor SNMP_VERSION = new 
PropertyDescriptor.Builder()
+            .name("snmp-version")
+            .displayName("SNMP Version")
+            .description("Three significant versions of SNMP have been 
developed and deployed. " +
+                    "SNMPv1 is the original version of the protocol. More 
recent versions, " +
+                    "SNMPv2c and SNMPv3, feature improvements in performance, 
flexibility and security.")
+            .required(true)
+            .allowableValues("SNMPv1", "SNMPv2c", "SNMPv3")
+            .defaultValue("SNMPv1")
+            .build();
+
+    public static final PropertyDescriptor SNMP_COMMUNITY = new 
PropertyDescriptor.Builder()
+            .name("snmp-community")
+            .displayName("SNMP Community")
+            .description("SNMPv1 and SNMPv2 use communities to establish trust 
between managers and agents." +
+                    " Most agents support three community names, one each for 
read-only, read-write and trap." +
+                    " These three community strings control different types of 
activities. The read-only community" +
+                    " applies to get requests. The read-write community string 
applies to set requests. The trap" +
+                    " community string applies to receipt of traps.")
+            .required(true)
+            .sensitive(true)
+            .defaultValue("public")
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1, SNMP_V2C)
+            .build();
+
+    public static final PropertyDescriptor SNMP_SECURITY_LEVEL = new 
PropertyDescriptor.Builder()
+            .name("snmp-security-level")
+            .displayName("SNMP Security Level")
+            .description("SNMP version 3 provides extra security with User 
Based Security Model (USM). The three levels of security is " +
+                    "1. Communication without authentication and encryption 
(NoAuthNoPriv). " +
+                    "2. Communication with authentication and without 
encryption (AuthNoPriv). " +
+                    "3. Communication with authentication and encryption 
(AuthPriv).")
+            .required(true)
+            .allowableValues(NO_AUTH_NO_PRIV, AUTH_NO_PRIV, AUTH_PRIV)
+            .defaultValue(NO_AUTH_NO_PRIV.getValue())
+            .dependsOn(SNMP_VERSION, SNMP_V3)
+            .build();
+
+    public static final PropertyDescriptor SNMP_USM_USERS_FILE_PATH = new 
PropertyDescriptor.Builder()
+            .name("snmp-usm-users-file-path")
+            .displayName("SNMP Users File Path")
+            .description("The path of the json file containing the user 
credentials for SNMPv3. Check Usage for more details.")
+            .required(true)
+            .defaultValue("")
+            .dependsOn(SNMP_VERSION, SNMP_V3)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("All FlowFiles that are received from the SNMP agent 
are routed to this relationship")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("All FlowFiles that cannot received from the SNMP 
agent are routed to this relationship")
+            .build();
+
+    protected static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS = 
Collections.unmodifiableList(Arrays.asList(
+            SNMP_MANAGER_PORT,
+            SNMP_VERSION,
+            SNMP_COMMUNITY,
+            SNMP_SECURITY_LEVEL,
+            SNMP_USM_USERS_FILE_PATH
+    ));
+
+    private static final Set<Relationship> RELATIONSHIPS = 
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+            REL_SUCCESS,
+            REL_FAILURE
+    )));
+
+    private volatile boolean isStarted = false;

Review comment:
       Instead of tracking `isStarted` separately from 
`SNMPTrapReceiverHandler`, would it make sense to have a property and 
corresponding method in `SNMPTrapReceiverHandler` itself indicated started 
status?

##########
File path: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/helper/configurations/SNMPConfigurations.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.helper.configurations;
+
+import org.apache.nifi.snmp.configuration.SNMPConfiguration;
+
+public interface SNMPConfigurations {
+
+    String DEFAULT_HOST = "127.0.0.1";
+    String COMMUNITY_STRING = "public";
+
+    // V3 security (users are set in test agents)
+    String SECURITY_LEVEL = "authPriv";
+    String SECURITY_NAME = "SHAAES128";
+    String AUTH_PROTOCOL = "SHA";
+    String AUTH_PASSPHRASE = "SHAAES128AuthPassphrase";
+    String PRIV_PROTOCOL = "AES128";
+    String PRIV_PASSPHRASE = "SHAAES128PrivPassphrase";

Review comment:
       Would it make more sense to define these values in one more or enums as 
opposed to interface properties?

##########
File path: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/SendTrapSNMP.java
##########
@@ -0,0 +1,269 @@
+/*
+ * 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 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.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+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.util.StandardValidators;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.snmp.configuration.TrapConfiguration;
+import org.apache.nifi.snmp.configuration.TrapV1Configuration;
+import org.apache.nifi.snmp.configuration.TrapV2cV3Configuration;
+import org.apache.nifi.snmp.utils.SNMPUtils;
+import org.snmp4j.mp.SnmpConstants;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Receiving data from configured SNMP agent which, upon each invocation of
+ * {@link #onTrigger(ProcessContext, ProcessSession)} method, will construct a
+ * {@link FlowFile} containing in its properties the information retrieved.
+ * The output {@link FlowFile} won't have any content.
+ */
+@Tags({"snmp", "send", "trap"})
+@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
+@CapabilityDescription("Sends information to SNMP Manager.")
+public class SendTrapSNMP extends AbstractSNMPProcessor {
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_0 = new 
AllowableValue("0", "Cold Start",
+            "A coldStart trap signifies that the sending protocol entity is 
reinitializing itself such that" +
+                    " the agent's configuration or the protocol entity 
implementation may be altered.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_1 = new 
AllowableValue("1", "Warm Start",
+            "A warmStart trap signifies that the sending protocol entity is 
reinitializing itself such that" +
+                    " neither the agent configuration nor the protocol entity 
implementation is altered.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_2 = new 
AllowableValue("2", "Link Down",
+            "A linkDown trap signifies that the sending protocol entity 
recognizes a failure in one of " +
+                    "the communication links represented in the agent's 
configuration.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_3 = new 
AllowableValue("3", "Link Up",
+            "A linkUp trap signifies that the sending protocol entity 
recognizes that one of the communication " +
+                    "links represented in the agent's configuration has come 
up.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_4 = new 
AllowableValue("4", "Authentication Failure",
+            "An authenticationFailure trap signifies that the sending protocol 
entity is the addressee of a " +
+                    "protocol message that is not properly authenticated.  
While implementations of the SNMP must be " +
+                    "capable of generating this trap, they must also be 
capable of suppressing the emission of such traps " +
+                    "via an implementation- specific mechanism.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_5 = new 
AllowableValue("5", "EGP Neighbor Loss",
+            "An egpNeighborLoss trap signifies that an EGP neighbor for whom 
the sending protocol entity was " +
+                    "an EGP peer has been marked down and the peer 
relationship no longer obtains.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_6 = new 
AllowableValue("6", "Enterprise Specific",
+            "An enterpriseSpecific trap signifies that a particular 
enterprise-specific trap has occurred which " +
+                    "can be defined in the Specific Trap Type field.");
+
+    public static final PropertyDescriptor SNMP_MANAGER_HOST = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-manager-host")
+            .displayName("SNMP Manager Host")
+            .description("The host where the SNMP Manager sends the trap.")
+            .required(true)
+            .defaultValue("localhost")
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .build();
+
+    public static final PropertyDescriptor SNMP_MANAGER_PORT = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-manager-port")
+            .displayName("SNMP Manager Port")
+            .description("The port where the SNMP Manager listens to the 
incoming traps.")
+            .required(true)
+            .defaultValue("0")
+            .addValidator(StandardValidators.PORT_VALIDATOR)
+            .build();
+
+    // SNMPv1 TRAP PROPERTIES
+
+    public static final PropertyDescriptor ENTERPRISE_OID = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-enterprise-oid")
+            .displayName("Enterprise OID")
+            .description("Enterprise is the vendor identification (OID) for 
the network management sub-system that generated the trap")
+            .required(true)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+    public static final PropertyDescriptor AGENT_ADDRESS = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-agent-address")
+            .displayName("SNMP Trap Agent Address")
+            .description("The address where the SNMP Manager sends the trap.")
+            .required(true)
+            .defaultValue("0")
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+
+    public static final PropertyDescriptor GENERIC_TRAP_TYPE = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-generic-type")
+            .displayName("Generic Trap Type")
+            .description("Generic trap type is an integer in the range of 0 to 
6. See Usage for details.")
+            .required(true)
+            .allowableValues(GENERIC_TRAP_TYPE_0, GENERIC_TRAP_TYPE_1, 
GENERIC_TRAP_TYPE_2, GENERIC_TRAP_TYPE_3,
+                    GENERIC_TRAP_TYPE_4, GENERIC_TRAP_TYPE_5, 
GENERIC_TRAP_TYPE_6)
+            .addValidator(StandardValidators.createLongValidator(0, 6, true))
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+
+    public static final PropertyDescriptor SPECIFIC_TRAP_TYPE = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-specific-type")
+            .displayName("Specific Trap Type")
+            .description("Specific trap type is a number that further 
specifies the nature of the event that generated " +
+                    "the trap in the case of traps of generic type 6 
(enterpriseSpecific). The interpretation of this " +
+                    "code is vendor-specific")
+            .required(true)
+            .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .dependsOn(GENERIC_TRAP_TYPE, GENERIC_TRAP_TYPE_6)
+            .build();
+
+    public static final PropertyDescriptor TIME_STAMP = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-timestamp")
+            .displayName("Timestamp")
+            .description("Timestamp of the trap (unit: 0.01 second).")
+            .required(true)
+            .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+
+    // SNMPv2c/v3 TRAP PROPERTIES
+
+    public static final PropertyDescriptor TRAP_OID_VALUE = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-oid-value")
+            .displayName("Trap OID Value")
+            .description("The value of the trap OID")
+            .required(false)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V2C, SNMP_V3)
+            .build();
+
+    public static final PropertyDescriptor SYSTEM_UPTIME = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-sysuptime")
+            .displayName("System Uptime")
+            .description("System uptime of the trap (unit: 0.01 second)")
+            .required(true)
+            .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V2C, SNMP_V3)
+            .build();
+
+    public static final Relationship REL_SUCCESS = new Relationship.Builder()
+            .name("success")
+            .description("All FlowFiles that are received from the SNMP agent 
are routed to this relationship")
+            .build();
+
+    public static final Relationship REL_FAILURE = new Relationship.Builder()
+            .name("failure")
+            .description("All FlowFiles that cannot received from the SNMP 
agent are routed to this relationship")
+            .build();
+
+    protected static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS = 
Collections.unmodifiableList(Arrays.asList(
+            SNMP_MANAGER_HOST,
+            SNMP_MANAGER_PORT,
+            SNMP_VERSION,
+            SNMP_COMMUNITY,
+            SNMP_SECURITY_LEVEL,
+            SNMP_SECURITY_NAME,
+            SNMP_AUTH_PROTOCOL,
+            SNMP_AUTH_PASSWORD,
+            SNMP_PRIVACY_PROTOCOL,
+            SNMP_PRIVACY_PASSWORD,
+            SNMP_RETRIES,
+            SNMP_TIMEOUT,
+            ENTERPRISE_OID,
+            AGENT_ADDRESS,
+            GENERIC_TRAP_TYPE,
+            SPECIFIC_TRAP_TYPE,
+            TIME_STAMP,
+            TRAP_OID_VALUE,
+            SYSTEM_UPTIME
+    ));
+
+    private static final Set<Relationship> RELATIONSHIPS = 
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+            REL_SUCCESS,
+            REL_FAILURE
+    )));
+
+    private volatile TrapConfiguration trapConfiguration;
+
+    @OnScheduled
+    public void init(ProcessContext context) throws InitializationException {
+        initSnmpManager(context);
+        final int snmpVersion = 
SNMPUtils.getVersion(context.getProperty(SNMP_VERSION).getValue());
+        if (SnmpConstants.version1 == snmpVersion) {
+            trapConfiguration = TrapV1Configuration.builder()
+                    
.enterpriseOid(context.getProperty(ENTERPRISE_OID).getValue())
+                    
.agentAddress(context.getProperty(AGENT_ADDRESS).getValue())
+                    
.genericTrapType(context.getProperty(GENERIC_TRAP_TYPE).asInteger())
+                    
.specificTrapType(context.getProperty(SPECIFIC_TRAP_TYPE).asInteger())
+                    .timeStamp(context.getProperty(TIME_STAMP).asInteger())
+                    .build();
+        } else {
+            trapConfiguration = new TrapV2cV3Configuration(
+                    context.getProperty(TRAP_OID_VALUE).getValue(),
+                    context.getProperty(SYSTEM_UPTIME).asInteger()
+            );
+        }
+    }
+
+    @Override
+    public void onTrigger(final ProcessContext context, final ProcessSession 
processSession) {
+        final FlowFile flowFile = processSession.get();
+        try {
+            snmpRequestHandler.sendTrap(trapConfiguration, flowFile);
+            if (flowFile != null) {
+                processSession.remove(flowFile);
+            }
+        } catch (IOException e) {
+            getLogger().error("Failed to send request to the agent. Check if 
the agent supports the used version.");

Review comment:
       It would be helpful to pass the exception to the logger for 
troubleshooting.

##########
File path: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/SendTrapSNMP.java
##########
@@ -0,0 +1,269 @@
+/*
+ * 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 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.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+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.util.StandardValidators;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.snmp.configuration.TrapConfiguration;
+import org.apache.nifi.snmp.configuration.TrapV1Configuration;
+import org.apache.nifi.snmp.configuration.TrapV2cV3Configuration;
+import org.apache.nifi.snmp.utils.SNMPUtils;
+import org.snmp4j.mp.SnmpConstants;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Receiving data from configured SNMP agent which, upon each invocation of
+ * {@link #onTrigger(ProcessContext, ProcessSession)} method, will construct a
+ * {@link FlowFile} containing in its properties the information retrieved.
+ * The output {@link FlowFile} won't have any content.
+ */
+@Tags({"snmp", "send", "trap"})
+@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
+@CapabilityDescription("Sends information to SNMP Manager.")
+public class SendTrapSNMP extends AbstractSNMPProcessor {
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_0 = new 
AllowableValue("0", "Cold Start",
+            "A coldStart trap signifies that the sending protocol entity is 
reinitializing itself such that" +
+                    " the agent's configuration or the protocol entity 
implementation may be altered.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_1 = new 
AllowableValue("1", "Warm Start",
+            "A warmStart trap signifies that the sending protocol entity is 
reinitializing itself such that" +
+                    " neither the agent configuration nor the protocol entity 
implementation is altered.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_2 = new 
AllowableValue("2", "Link Down",
+            "A linkDown trap signifies that the sending protocol entity 
recognizes a failure in one of " +
+                    "the communication links represented in the agent's 
configuration.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_3 = new 
AllowableValue("3", "Link Up",
+            "A linkUp trap signifies that the sending protocol entity 
recognizes that one of the communication " +
+                    "links represented in the agent's configuration has come 
up.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_4 = new 
AllowableValue("4", "Authentication Failure",
+            "An authenticationFailure trap signifies that the sending protocol 
entity is the addressee of a " +
+                    "protocol message that is not properly authenticated.  
While implementations of the SNMP must be " +
+                    "capable of generating this trap, they must also be 
capable of suppressing the emission of such traps " +
+                    "via an implementation- specific mechanism.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_5 = new 
AllowableValue("5", "EGP Neighbor Loss",
+            "An egpNeighborLoss trap signifies that an EGP neighbor for whom 
the sending protocol entity was " +
+                    "an EGP peer has been marked down and the peer 
relationship no longer obtains.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_6 = new 
AllowableValue("6", "Enterprise Specific",
+            "An enterpriseSpecific trap signifies that a particular 
enterprise-specific trap has occurred which " +
+                    "can be defined in the Specific Trap Type field.");
+
+    public static final PropertyDescriptor SNMP_MANAGER_HOST = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-manager-host")
+            .displayName("SNMP Manager Host")
+            .description("The host where the SNMP Manager sends the trap.")
+            .required(true)
+            .defaultValue("localhost")
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .build();
+
+    public static final PropertyDescriptor SNMP_MANAGER_PORT = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-manager-port")
+            .displayName("SNMP Manager Port")
+            .description("The port where the SNMP Manager listens to the 
incoming traps.")
+            .required(true)
+            .defaultValue("0")
+            .addValidator(StandardValidators.PORT_VALIDATOR)

Review comment:
       Based on the standard PORT_VALIDATOR, is the default value of `0` 
invalid?

##########
File path: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/SetSNMP.java
##########
@@ -105,6 +113,8 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession process
                 getLogger().error("Failed to send request to the agent. Check 
if the agent supports the used version.");
                 processError(context, processSession, flowFile);
             }
+        } else {
+            throw new ProcessException("No incoming flowfile found.");

Review comment:
       Not quite following the reason for throwing a ProcessException here, is 
it not acceptable for the processor to be triggered without input files?

##########
File path: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/SendTrapSNMP.java
##########
@@ -0,0 +1,269 @@
+/*
+ * 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 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.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+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.util.StandardValidators;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.snmp.configuration.TrapConfiguration;
+import org.apache.nifi.snmp.configuration.TrapV1Configuration;
+import org.apache.nifi.snmp.configuration.TrapV2cV3Configuration;
+import org.apache.nifi.snmp.utils.SNMPUtils;
+import org.snmp4j.mp.SnmpConstants;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Receiving data from configured SNMP agent which, upon each invocation of
+ * {@link #onTrigger(ProcessContext, ProcessSession)} method, will construct a
+ * {@link FlowFile} containing in its properties the information retrieved.
+ * The output {@link FlowFile} won't have any content.
+ */
+@Tags({"snmp", "send", "trap"})
+@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
+@CapabilityDescription("Sends information to SNMP Manager.")
+public class SendTrapSNMP extends AbstractSNMPProcessor {
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_0 = new 
AllowableValue("0", "Cold Start",
+            "A coldStart trap signifies that the sending protocol entity is 
reinitializing itself such that" +
+                    " the agent's configuration or the protocol entity 
implementation may be altered.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_1 = new 
AllowableValue("1", "Warm Start",
+            "A warmStart trap signifies that the sending protocol entity is 
reinitializing itself such that" +
+                    " neither the agent configuration nor the protocol entity 
implementation is altered.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_2 = new 
AllowableValue("2", "Link Down",
+            "A linkDown trap signifies that the sending protocol entity 
recognizes a failure in one of " +
+                    "the communication links represented in the agent's 
configuration.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_3 = new 
AllowableValue("3", "Link Up",
+            "A linkUp trap signifies that the sending protocol entity 
recognizes that one of the communication " +
+                    "links represented in the agent's configuration has come 
up.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_4 = new 
AllowableValue("4", "Authentication Failure",
+            "An authenticationFailure trap signifies that the sending protocol 
entity is the addressee of a " +
+                    "protocol message that is not properly authenticated.  
While implementations of the SNMP must be " +
+                    "capable of generating this trap, they must also be 
capable of suppressing the emission of such traps " +
+                    "via an implementation- specific mechanism.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_5 = new 
AllowableValue("5", "EGP Neighbor Loss",
+            "An egpNeighborLoss trap signifies that an EGP neighbor for whom 
the sending protocol entity was " +
+                    "an EGP peer has been marked down and the peer 
relationship no longer obtains.");
+
+    public static final AllowableValue GENERIC_TRAP_TYPE_6 = new 
AllowableValue("6", "Enterprise Specific",
+            "An enterpriseSpecific trap signifies that a particular 
enterprise-specific trap has occurred which " +
+                    "can be defined in the Specific Trap Type field.");
+
+    public static final PropertyDescriptor SNMP_MANAGER_HOST = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-manager-host")
+            .displayName("SNMP Manager Host")
+            .description("The host where the SNMP Manager sends the trap.")
+            .required(true)
+            .defaultValue("localhost")
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .build();
+
+    public static final PropertyDescriptor SNMP_MANAGER_PORT = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-manager-port")
+            .displayName("SNMP Manager Port")
+            .description("The port where the SNMP Manager listens to the 
incoming traps.")
+            .required(true)
+            .defaultValue("0")
+            .addValidator(StandardValidators.PORT_VALIDATOR)
+            .build();
+
+    // SNMPv1 TRAP PROPERTIES
+
+    public static final PropertyDescriptor ENTERPRISE_OID = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-enterprise-oid")
+            .displayName("Enterprise OID")
+            .description("Enterprise is the vendor identification (OID) for 
the network management sub-system that generated the trap")
+            .required(true)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+    public static final PropertyDescriptor AGENT_ADDRESS = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-agent-address")
+            .displayName("SNMP Trap Agent Address")
+            .description("The address where the SNMP Manager sends the trap.")
+            .required(true)
+            .defaultValue("0")
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+
+    public static final PropertyDescriptor GENERIC_TRAP_TYPE = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-generic-type")
+            .displayName("Generic Trap Type")
+            .description("Generic trap type is an integer in the range of 0 to 
6. See Usage for details.")
+            .required(true)
+            .allowableValues(GENERIC_TRAP_TYPE_0, GENERIC_TRAP_TYPE_1, 
GENERIC_TRAP_TYPE_2, GENERIC_TRAP_TYPE_3,
+                    GENERIC_TRAP_TYPE_4, GENERIC_TRAP_TYPE_5, 
GENERIC_TRAP_TYPE_6)
+            .addValidator(StandardValidators.createLongValidator(0, 6, true))
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+
+    public static final PropertyDescriptor SPECIFIC_TRAP_TYPE = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-specific-type")
+            .displayName("Specific Trap Type")
+            .description("Specific trap type is a number that further 
specifies the nature of the event that generated " +
+                    "the trap in the case of traps of generic type 6 
(enterpriseSpecific). The interpretation of this " +
+                    "code is vendor-specific")
+            .required(true)
+            .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .dependsOn(GENERIC_TRAP_TYPE, GENERIC_TRAP_TYPE_6)
+            .build();
+
+    public static final PropertyDescriptor TIME_STAMP = new 
PropertyDescriptor.Builder()
+            .name("snmp-trap-timestamp")
+            .displayName("Timestamp")
+            .description("Timestamp of the trap (unit: 0.01 second).")
+            .required(true)
+            .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
+            .dependsOn(SNMP_VERSION, SNMP_V1)
+            .build();
+
+    // SNMPv2c/v3 TRAP PROPERTIES

Review comment:
       Is this comment necessary?




-- 
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:
[email protected]


Reply via email to