Class SnmpMessageTree
java.lang.Object
com.snmp4j.smi.ber.SnmpMessageTree
Parses a raw SNMP message byte array into a
BERNode tree that reflects the
BER (Basic Encoding Rules) structure of the message. Supports SNMPv1, SNMPv2c, and
SNMPv3, including decryption of AUTH_PRIV ScopedPDUs when matching
DirectUserTarget credentials are provided.
The resulting tree can be rendered as indented text (formatAsText(BERNode)) or as
a JSON object tree (formatAsJson(BERNode)).
- Since:
- 2.0.0
- Author:
- Frank Fock
-
Constructor Summary
ConstructorsConstructorDescriptionSnmpMessageTree(List<? extends org.snmp4j.DirectUserTarget<?>> targets) Creates a newSnmpMessageTreeinstance. -
Method Summary
Modifier and TypeMethodDescriptionbuildTreeOfBER(byte[] messageBytes) ParsemessageBytesand return the rootBERNodeof the BER tree.formatAsJson(BERNode root) Render the BER node tree as a JSON object tree (pretty-printed, 2-space indent).formatAsText(BERNode root) Render the BER node tree as an indented text tree using box-drawing characters.static StringReturn the JSON Schema (Draft 2020-12) describing theBERNode/BERNodeErrorJSON structure produced byformatAsJson(BERNode).
-
Constructor Details
-
SnmpMessageTree
Creates a newSnmpMessageTreeinstance.- Parameters:
targets- SNMPv3 credentials for decrypting AUTH_PRIV messages; may be null (decryption will be skipped). Targets that have a non-emptyauthoritativeEngineIDare used as-is (their keys must already be localized). Targets without an engine ID are kept in a deferred pool: when the packet's engine ID is extracted at parse time, their passphrase is localized on the fly.
-
-
Method Details
-
buildTreeOfBER
ParsemessageBytesand return the rootBERNodeof the BER tree. Errors are represented asBERNodeErrorleaf nodes rather than thrown.- Parameters:
messageBytes- the message bytes to parse- Returns:
- the root
BERNodeof the BER tree
-
formatAsText
Render the BER node tree as an indented text tree using box-drawing characters.SEQUENCE (SNMP Message) [tag=0x30, pos=0, len=117] ├── INTEGER (version) = 1 → SNMPv2c [tag=0x02, pos=2, len=3] └── GetResponse-PDU [tag=0xa2, pos=13, len=104] ├── ...- Parameters:
root- the rootBERNodeof the BER tree to render- Returns:
- the rendered text tree.
-
formatAsJson
-
getBerNodeJsonSchema
Return the JSON Schema (Draft 2020-12) describing theBERNode/BERNodeErrorJSON structure produced byformatAsJson(BERNode).- Returns:
- the JSON Schema.
-