NIFI-9569: SNMP manager UDP transportmapping changed to 0.0.0.0

This closes .

Signed-off-by: Peter Turcsanyi <turcsanyi@apache.org>
This commit is contained in:
Lehel 2022-01-20 19:20:04 +01:00 committed by Peter Turcsanyi
parent 3d36a17185
commit ec26ec9904
7 changed files with 16 additions and 18 deletions
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src

View File

@ -26,13 +26,11 @@ import java.io.IOException;
public class SNMPManagerFactory {
private static final String LOCALHOST = "127.0.0.1";
public Snmp createSnmpManagerInstance(final SNMPConfiguration configuration) {
final String managerAddress = LOCALHOST + "/" + configuration.getManagerPort();
final int port = configuration.getManagerPort();
final Snmp snmpManager;
try {
snmpManager = new Snmp(new DefaultUdpTransportMapping(new UdpAddress(managerAddress)));
snmpManager = new Snmp(new DefaultUdpTransportMapping(new UdpAddress(port)));
snmpManager.listen();
} catch (IOException e) {
throw new ProcessException(e);

View File

@ -21,7 +21,7 @@ import org.junit.Test;
import org.snmp4j.mp.SnmpConstants;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.COMMUNITY_STRING;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.DEFAULT_HOST;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
@ -42,7 +42,7 @@ public class SNMPConfigurationTest {
public void testMembersAreSetCorrectly() {
final SNMPConfiguration snmpConfiguration = SNMPConfiguration.builder()
.setManagerPort(MANAGER_PORT)
.setTargetHost(DEFAULT_HOST)
.setTargetHost(LOCALHOST)
.setTargetPort(TARGET_PORT)
.setRetries(RETRIES)
.setTimeoutInMs(TIMEOUT_IN_MS)
@ -57,7 +57,7 @@ public class SNMPConfigurationTest {
.build();
assertEquals(MANAGER_PORT, snmpConfiguration.getManagerPort());
assertEquals(DEFAULT_HOST, snmpConfiguration.getTargetHost());
assertEquals(LOCALHOST, snmpConfiguration.getTargetHost());
assertEquals(TARGET_PORT, snmpConfiguration.getTargetPort());
assertEquals(RETRIES, snmpConfiguration.getRetries());
assertEquals(TIMEOUT_IN_MS, snmpConfiguration.getTimeoutInMs());

View File

@ -25,7 +25,7 @@ import org.snmp4j.Snmp;
import org.snmp4j.Target;
import org.snmp4j.security.SecurityLevel;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.DEFAULT_HOST;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
@ -46,7 +46,7 @@ public class V1V2cSNMPFactoryTest {
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
assertThat(target, instanceOf(CommunityTarget.class));
assertEquals(DEFAULT_HOST + "/" + targetPort, target.getAddress().toString());
assertEquals(LOCALHOST + "/" + targetPort, target.getAddress().toString());
assertEquals(RETRIES, target.getRetries());
assertEquals(1, target.getSecurityLevel());
assertEquals(StringUtils.EMPTY, target.getSecurityName().toString());
@ -62,7 +62,7 @@ public class V1V2cSNMPFactoryTest {
final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
final String address = snmpManager.getMessageDispatcher().getTransportMappings().iterator().next().getListenAddress().toString();
assertEquals(DEFAULT_HOST + "/" + managerPort, address);
assertEquals("0.0.0.0" + "/" + managerPort, address);
}
@Test
@ -82,7 +82,7 @@ public class V1V2cSNMPFactoryTest {
return new SNMPConfiguration.Builder()
.setRetries(RETRIES)
.setManagerPort(managerPort)
.setTargetHost(DEFAULT_HOST)
.setTargetHost(LOCALHOST)
.setTargetPort(targetPort)
.setSecurityLevel(SecurityLevel.noAuthNoPriv.name())
.build();

View File

@ -28,7 +28,7 @@ import org.snmp4j.security.USM;
import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.OctetString;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.DEFAULT_HOST;
import static org.apache.nifi.snmp.helper.configurations.SNMPConfigurationFactory.LOCALHOST;
import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PASSPHRASE;
import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.AUTH_PROTOCOL;
import static org.apache.nifi.snmp.helper.configurations.SNMPV3ConfigurationFactory.PRIV_PASSPHRASE;
@ -56,7 +56,7 @@ public class V3SNMPFactoryTest {
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
assertThat(target, instanceOf(UserTarget.class));
assertEquals(DEFAULT_HOST + "/" + targetPort, target.getAddress().toString());
assertEquals(LOCALHOST + "/" + targetPort, target.getAddress().toString());
assertEquals(RETRIES, target.getRetries());
assertEquals(EXPECTED_SECURITY_LEVEL, target.getSecurityLevel());
assertEquals(SECURITY_NAME, target.getSecurityName().toString());
@ -73,7 +73,7 @@ public class V3SNMPFactoryTest {
final String address = snmpManager.getMessageDispatcher().getTransportMappings().iterator().next().getListenAddress().toString();
USM usm = (USM) SecurityModels.getInstance().getSecurityModel(new Integer32(3));
assertEquals(DEFAULT_HOST + "/" + managerPort, address);
assertEquals("0.0.0.0" + "/" + managerPort, address);
assertTrue(usm.hasUser(null, new OctetString("SHAAES128")));
}
@ -93,7 +93,7 @@ public class V3SNMPFactoryTest {
return new SNMPConfiguration.Builder()
.setRetries(RETRIES)
.setManagerPort(managerPort)
.setTargetHost(DEFAULT_HOST)
.setTargetHost(LOCALHOST)
.setTargetPort(targetPort)
.setSecurityLevel(SecurityLevel.authPriv.name())
.setSecurityName(SECURITY_NAME)

View File

@ -20,7 +20,7 @@ import org.apache.nifi.snmp.configuration.SNMPConfiguration;
public interface SNMPConfigurationFactory {
String DEFAULT_HOST = "127.0.0.1";
String LOCALHOST = "127.0.0.1";
String COMMUNITY_STRING = "public";
SNMPConfiguration createSnmpGetSetConfiguration(int agentPort);

View File

@ -29,7 +29,7 @@ public class SNMPV1V2cConfigurationFactory implements SNMPConfigurationFactory {
@Override
public SNMPConfiguration createSnmpGetSetConfiguration(final int agentPort) {
return SNMPConfiguration.builder()
.setTargetHost(DEFAULT_HOST)
.setTargetHost(LOCALHOST)
.setTargetPort(String.valueOf(agentPort))
.setCommunityString(COMMUNITY_STRING)
.setVersion(snmpVersion)

View File

@ -32,7 +32,7 @@ public class SNMPV3ConfigurationFactory implements SNMPConfigurationFactory {
@Override
public SNMPConfiguration createSnmpGetSetConfiguration(final int agentPort) {
return SNMPConfiguration.builder()
.setTargetHost(DEFAULT_HOST)
.setTargetHost(LOCALHOST)
.setTargetPort(String.valueOf(agentPort))
.setCommunityString(COMMUNITY_STRING)
.setVersion(SnmpConstants.version3)