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 2021/07/12 19:49:50 UTC

[GitHub] [nifi] Lehel44 commented on a change in pull request #5088: NIFI-3320: SendTrapSNMP and ListenTrapSNMP processors added.

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



##########
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:
       @exceptionfactory Would you please go into detail here? I'd like to grasp the underlying issue.

##########
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:
       As for me they're fine here for the unit tests. Do you think I should move them?




-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org