[
https://issues.apache.org/jira/browse/NIFI-1537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15185040#comment-15185040
]
ASF GitHub Bot commented on NIFI-1537:
--------------------------------------
Github user olegz commented on a diff in the pull request:
https://github.com/apache/nifi/pull/257#discussion_r55371374
--- Diff:
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/processors/SetSNMPTest.java
---
@@ -0,0 +1,411 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.snmp4j.AbstractTarget;
+import org.snmp4j.CommunityTarget;
+import org.snmp4j.Snmp;
+import org.snmp4j.agent.mo.DefaultMOFactory;
+import org.snmp4j.agent.mo.MOAccessImpl;
+import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.smi.Integer32;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
+
+/**
+ * Class to test SNMP Get processor
+ */
+public class SetSNMPTest {
+
+ /** agent for version v1 */
+ private static TestSnmpAgentV1 agentv1 = null;
+ /** agent for version v2c */
+ private static TestSnmpAgentV2c agentv2c = null;
+ /** OID for system description */
+ private static final OID sysDescr = new OID("1.3.6.1.2.1.1.1.0");
+ /** value we set for system description at set-up */
+ private static final String value = "MySystemDescr";
+ /** OID for read only access */
+ private static final OID readOnlyOID = new OID("1.3.6.1.2.1.1.3.0");
+ /** value we set for read only at set-up */
+ private static final int readOnlyValue = 1;
+ /** OID for write only access */
+ private static final OID writeOnlyOID = new OID("1.3.6.1.2.1.1.3.0");
+ /** value we set for write only at set-up */
+ private static final int writeOnlyValue = 1;
+
+ /**
+ * Method to set up different SNMP agents
+ * @throws Exception Exception
+ */
+ @BeforeClass
+ public static void setUp() throws Exception {
+ agentv2c = new TestSnmpAgentV2c("0.0.0.0/2001");
+ agentv2c.start();
+ agentv2c.unregisterManagedObject(agentv2c.getSnmpv2MIB());
+ agentv2c.registerManagedObject(
+ DefaultMOFactory.getInstance().createScalar(sysDescr,
+ MOAccessImpl.ACCESS_READ_WRITE,
+ new OctetString(value)));
+ agentv2c.registerManagedObject(
+ DefaultMOFactory.getInstance().createScalar(readOnlyOID,
+ MOAccessImpl.ACCESS_READ_ONLY,
+ new Integer32(readOnlyValue)));
+
+ agentv1 = new TestSnmpAgentV1("0.0.0.0/2002");
+ agentv1.start();
+ agentv1.unregisterManagedObject(agentv1.getSnmpv2MIB());
+ agentv1.registerManagedObject(
+ DefaultMOFactory.getInstance().createScalar(sysDescr,
+ MOAccessImpl.ACCESS_READ_WRITE,
+ new OctetString(value)));
+ agentv1.registerManagedObject(
+ DefaultMOFactory.getInstance().createScalar(writeOnlyOID,
+ MOAccessImpl.ACCESS_WRITE_ONLY,
+ new Integer32(writeOnlyValue)));
+ }
+
+ /**
+ * Method to close SNMP Agent once the tests are completed
+ * @throws Exception Exception
+ */
+ @AfterClass
+ public static void tearDown() throws Exception {
+ agentv1.stop();
+ agentv2c.stop();
+ }
+
+ // /**
+ // * Test to check FlowFile handling when performing a SNMP Get.
+ // * First we set a new value for the OID we want to request, then
we
+ // * request this OID and we check that the returned value if the
one
+ // * we set just before.
+ // * @throws Exception Exception
+ // */
+ // @Test
+ // public void validateSuccessfullSnmpSetv2c() throws Exception {
+ // Snmp snmp = SNMPUtilsTest.createSnmp();
+ // CommunityTarget target =
SNMPUtilsTest.createCommTarget("public", "127.0.0.1/2001",
SnmpConstants.version2c);
+ //
+ // try (SNMPSetter setter = new SNMPSetter(snmp, target)) {
+ // PDU pdu = new PDU();
+ // pdu.add(new VariableBinding(new OID(sysDescr), new
OctetString("test")));
+ // pdu.setType(PDU.SET);
+ // ResponseEvent response = setter.set(pdu);
+ // if(response.getResponse().getErrorStatus() !=
PDU.noError ) {
+ // fail();
+ // }
+ // Thread.sleep(200);
+ //
+ // SetSNMP pubProc = new LocalSetSnmp(snmp, target);
+ // TestRunner runner = TestRunners.newTestRunner(pubProc);
+ //
+ // runner.setProperty(SetSNMP.OID, sysDescr.toString());
+ // runner.setProperty(SetSNMP.HOST, "127.0.0.1");
+ // runner.setProperty(SetSNMP.PORT, "2002");
+ // runner.setProperty(SetSNMP.SNMP_COMMUNITY, "public");
+ // runner.setProperty(SetSNMP.SNMP_VERSION, "SNMPv1");
+ //
+ // runner.run();
+ // Thread.sleep(200);
+ // final MockFlowFile successFF =
runner.getFlowFilesForRelationship(SetSNMP.REL_SUCCESS).get(0);
+ // assertNotNull(successFF);
+ // assertEquals("test",
successFF.getAttributes().get(SNMPUtils.SNMP_PROP_PREFIX +
sysDescr.toString()));
+ // }
+ // }
+ //
+ // /**
+ // * Test to check FlowFile handling when performing a SNMP Get.
+ // * First we set a new value for the OID we want to request, then
we
+ // * request this OID and we check that the returned value if the
one
+ // * we set just before.
+ // * @throws Exception Exception
+ // */
+ // @Test
+ // public void validateSuccessfullSnmpSetv1() throws Exception {
+ // Snmp snmp = SNMPUtilsTest.createSnmp();
+ // CommunityTarget target =
SNMPUtilsTest.createCommTarget("public", "127.0.0.1/2002",
SnmpConstants.version1);
+ //
+ // try (SNMPSetter setter = new SNMPSetter(snmp, target)) {
+ // PDU pdu = new PDU();
+ // pdu.add(new VariableBinding(new OID(sysDescr), new
OctetString("test")));
+ // pdu.setType(PDU.SET);
+ // ResponseEvent response = setter.set(pdu);
+ // if(response.getResponse().getErrorStatus() !=
PDU.noError ) {
+ // fail();
+ // }
+ // Thread.sleep(200);
+ //
+ // SetSNMP pubProc = new LocalSetSnmp(snmp, target);
+ // TestRunner runner = TestRunners.newTestRunner(pubProc);
+ //
+ // runner.setProperty(SetSNMP.OID, sysDescr.toString());
+ // runner.setProperty(SetSNMP.HOST, "127.0.0.1");
+ // runner.setProperty(SetSNMP.PORT, "2002");
+ // runner.setProperty(SetSNMP.SNMP_COMMUNITY, "public");
+ // runner.setProperty(SetSNMP.SNMP_VERSION, "SNMPv1");
+ //
+ // runner.run();
+ // Thread.sleep(200);
+ // final MockFlowFile successFF =
runner.getFlowFilesForRelationship(SetSNMP.REL_SUCCESS).get(0);
+ // assertNotNull(successFF);
+ // assertEquals("test",
successFF.getAttributes().get(SNMPUtils.SNMP_PROP_PREFIX +
sysDescr.toString()));
+ // }
+ // }
+
--- End diff --
Pierre, did you intent to keep commented code above?
> 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)