diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index f50e919e3d..a88ace58ae 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1242,8 +1242,10 @@ transport: snmp: # Enable/disable SNMP transport protocol enabled: "${SNMP_ENABLED:true}" - # Snmp bind port - bind_port: "${SNMP_BIND_PORT:1620}" + # SNMP bind address + bind_address: "${SNMP_BIND_ADDRESS:0.0.0.0}" + # SNMP bind port. Zero (random) by default. When using SNMP TRAPs - make sure to specify some static value, e.g. 1620 + bind_port: "${SNMP_BIND_PORT:0}" response_processing: # parallelism level for executor (workStealingPool) that is responsible for handling responses from SNMP devices parallelism_level: "${SNMP_RESPONSE_PROCESSING_PARALLELISM_LEVEL:4}" diff --git a/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/service/SnmpTransportService.java b/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/service/SnmpTransportService.java index 04f113b918..66c14ca8ee 100644 --- a/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/service/SnmpTransportService.java +++ b/common/transport/snmp/src/main/java/org/thingsboard/server/transport/snmp/service/SnmpTransportService.java @@ -67,6 +67,7 @@ import org.thingsboard.server.transport.snmp.session.DeviceSessionContext; import org.thingsboard.server.transport.snmp.session.ScheduledTask; import java.io.IOException; +import java.net.InetAddress; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -97,8 +98,10 @@ public class SnmpTransportService implements TbTransportService, CommandResponde private final Map responseDataMappers = new EnumMap<>(SnmpCommunicationSpec.class); private final Map responseProcessors = new EnumMap<>(SnmpCommunicationSpec.class); - @Value("${transport.snmp.bind_port:1620}") + @Value("${transport.snmp.bind_port:0}") private Integer snmpBindPort; + @Value("${transport.snmp.bind_address:0.0.0.0}") + private String snmpBindAddress; @Value("${transport.snmp.response_processing.parallelism_level:4}") private int responseProcessingThreadPoolSize; @Value("${transport.snmp.scheduler_thread_pool_size:4}") @@ -134,10 +137,10 @@ public class SnmpTransportService implements TbTransportService, CommandResponde TransportMapping transportMapping; switch (snmpUnderlyingProtocol) { case "udp": - transportMapping = new DefaultUdpTransportMapping(new UdpAddress(snmpBindPort)); + transportMapping = new DefaultUdpTransportMapping(new UdpAddress(InetAddress.getByName(snmpBindAddress), snmpBindPort)); break; case "tcp": - transportMapping = new DefaultTcpTransportMapping(new TcpAddress(snmpBindPort)); + transportMapping = new DefaultTcpTransportMapping(new TcpAddress(InetAddress.getByName(snmpBindAddress), snmpBindPort)); break; default: throw new IllegalArgumentException("Underlying protocol " + snmpUnderlyingProtocol + " for SNMP is not supported");