Merge pull request #12734 from artem-barysh-dev/fix-snmp

SNMP: fix request sending failure
This commit is contained in:
Viacheslav Klimov 2025-02-24 15:16:08 +02:00 committed by GitHub
commit 49f2a071c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View File

@ -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}"

View File

@ -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<SnmpCommunicationSpec, ResponseDataMapper> responseDataMappers = new EnumMap<>(SnmpCommunicationSpec.class);
private final Map<SnmpCommunicationSpec, ResponseProcessor> 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");