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



##########
File path: 
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/context/SNMPContext.java
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.context;
+
+import org.apache.nifi.snmp.configuration.BasicConfiguration;
+import org.apache.nifi.snmp.configuration.SecurityConfiguration;
+import org.apache.nifi.snmp.exception.AgentSecurityConfigurationException;
+import org.apache.nifi.snmp.utils.SNMPUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.snmp4j.AbstractTarget;
+import org.snmp4j.CommunityTarget;
+import org.snmp4j.Snmp;
+import org.snmp4j.UserTarget;
+import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.security.SecurityLevel;
+import org.snmp4j.security.UsmUser;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.UdpAddress;
+import org.snmp4j.transport.DefaultUdpTransportMapping;
+
+import java.io.IOException;
+
+public class SNMPContext {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SNMPContext.class);
+
+    private Snmp snmp;
+    private AbstractTarget target;
+
+    public static SNMPContext newInstance() {
+        return new SNMPContext();
+    }
+
+    public void init(final BasicConfiguration basicConfiguration, final 
SecurityConfiguration securityConfiguration) {
+        initSnmp(basicConfiguration);
+
+        final String snmpVersion = securityConfiguration.getVersion();
+
+        final int version = SNMPUtils.getSnmpVersion(snmpVersion);
+
+        if (version == SnmpConstants.version3) {
+            createUserTarget(basicConfiguration, securityConfiguration, snmp, 
version);
+        } else {
+            target = createCommunityTarget(basicConfiguration, 
securityConfiguration, version);
+        }
+    }
+
+    public void close() {
+        try {
+            snmp.close();
+        } catch (IOException e) {
+            LOGGER.error("Could not close SNMP session.");

Review comment:
       Changed it.




-- 
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:
us...@infra.apache.org


Reply via email to