Fixed bulk SNMP operations by making the protocol version configurable - #2160
Open
cafe-jun wants to merge 1 commit into
Open
Fixed bulk SNMP operations by making the protocol version configurable#2160cafe-jun wants to merge 1 commit into
cafe-jun wants to merge 1 commit into
Conversation
The connector hardcoded credentials.V1, so every request was sent as SNMPv1. GETBULK was introduced in SNMPv2c, so agents discard the PDU and the client times out. This made bulkget, bulkwalk and bulktable unusable, even though all three are advertised as supported methods. Added an optional per-device "version" key accepting "v1" or "v2c", defaulting to "v2c". SNMPv1-only agents remain reachable by setting it explicitly. An unknown value logs a warning and falls back to the default instead of breaking the poll. Closes thingsboard#2150
cafe-jun
force-pushed
the
fix/snmp-version-config
branch
from
August 24, 2026 11:25
7b1f849 to
1b60f68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2150
Problem
SNMPConnectorhardcodescredentials.V1, so every request goes out with the SNMP version field set to0(SNMPv1):https://github.com/thingsboard/thingsboard-gateway/blob/master/thingsboard_gateway/connectors/snmp/snmp_connector.py#L171-L173
GETBULK was introduced in SNMPv2c. Carried inside an SNMPv1 message it is discarded by the agent, and the client times out — the
TimeoutErrorreported in #2150.This is not limited to
bulkwalk. Three of the eleven advertised methods are built on GETBULK and are therefore unusable:bulkgetbulkwalkbulktableIn
puresnmp,V2CsubclassesV1and overrides onlympm(0→1), which is the version field in the packet. The credential class alone decides whether bulk operations can work.Reproduction
Against a local
snmpsimagent (communitypublic), walking1.3.6.1.2.1.2.2.1.2(3 entries):getbulkwalkV1(current)Timeout: 3 second timeout exceeded on UDP transport.V2CChange
Adds an optional per-device
versionkey acceptingv1orv2c, defaulting tov2c. SNMPv1-only agents stay reachable by setting it explicitly. An unknown value logs a warning and falls back to the default rather than breaking the poll.The key is also added to the shipped
config/snmp.jsonexample so it is discoverable.Verification
Exercised through
SNMPConnector.__process_methodsagainst the same agent:versionkeyv2cbulkwalk"version": "v1"v1bulkwalk"version": "v1"v1get"version": "V2C"v2cbulkwalk"version": "v9"bulkwalkOn the default value
I defaulted to
v2cbecause the connector advertises bulk methods that cannot work under v1, andpuresnmpitself emitsUserWarning: Experimental SNMPv1 support. This does change behaviour for anyone relying on the implicit v1, so if you would rather keepv1as the default and have users opt intov2c, say the word and I will flip it — the change is one constant.Notes
tests/. Happy to add unit tests for the version resolution if you want them in this PR.config/snmp.jsonshows a per-datapoint"community"override, while the connector only readsdevice["community"]. I left it alone to keep this change focused.v3is not included since it needs auth/priv parameters and a wider config surface.