SnmpKit.SnmpLib (snmpkit v2.0.0)
Protocol layer of SnmpKit: RFC-compliant PDU encoding and decoding, ASN.1 BER, OID utilities, SNMP data types, UDP transport, a low-level manager and the SNMPv3 User-based Security Model.
Most applications use SnmpKit.SNMP instead; this layer is for code that
needs to build or inspect SNMP messages directly.
Modules
SnmpKit.SnmpLib.PDU- PDU and message encoding/decoding for SNMPv1, v2c and v3, including the v2c exception valuesnoSuchObject,noSuchInstanceandendOfMibViewSnmpKit.SnmpLib.ASN1- BER primitives, with correct multibyte OID sub-identifiers (X.690)SnmpKit.SnmpLib.OID- string/list conversion, comparison, tree and table-index helpersSnmpKit.SnmpLib.Types- validation and formatting of SNMP typesSnmpKit.SnmpLib.Transport- UDP sockets and address handlingSnmpKit.SnmpLib.Manager- GET, GETNEXT, GETBULK and SET against one host, returning{type, value}tuplesSnmpKit.SnmpLib.Walker- GETNEXT/GETBULK walks at this levelSnmpKit.SnmpLib.ErrorHandler- retry with exponential backoff, error classification, adaptive timeouts, device quarantineSnmpKit.SnmpLib.SecurityandSecurity.{USM, Auth, Priv, Keys}- SNMPv3 USM per RFC 3414 (MD5, SHA-1, SHA-2 family per RFC 7860; DES and AES-128/192/256)
Examples
# One GET against a host, raw {type, value} result
{:ok, {:octet_string, description}} =
SnmpKit.SnmpLib.Manager.get("192.168.1.1", [1, 3, 6, 1, 2, 1, 1, 1, 0])
# Retry with exponential backoff
SnmpKit.SnmpLib.ErrorHandler.with_retry(fn ->
SnmpKit.SnmpLib.Manager.get("flaky.device", [1, 3, 6, 1, 2, 1, 1, 1, 0])
end, max_attempts: 5, base_delay: 2000)
# Encode a GET request PDU
iex> pdu = SnmpKit.SnmpLib.PDU.build_get_request([1, 3, 6, 1, 2, 1, 1, 1, 0], 12345)
iex> message = SnmpKit.SnmpLib.PDU.build_message(pdu, "public", :v2c)
iex> {:ok, encoded} = SnmpKit.SnmpLib.PDU.encode_message(message)
iex> is_binary(encoded)
true
# Build a GETBULK request (SNMPv2c)
iex> bulk_pdu = SnmpKit.SnmpLib.PDU.build_get_bulk_request([1, 3, 6, 1, 2, 1, 2, 2], 456, 0, 10)
iex> bulk_pdu.type
:get_bulk_request
# OID manipulation with multibyte values
iex> {:ok, oid_list} = SnmpKit.SnmpLib.OID.string_to_list("1.3.6.1.4.1.200.1")
iex> oid_list
[1, 3, 6, 1, 4, 1, 200, 1]
iex> {:ok, oid_string} = SnmpKit.SnmpLib.OID.list_to_string([1, 3, 6, 1, 4, 1, 200, 1])
iex> oid_string
"1.3.6.1.4.1.200.1"
# SNMPv2c exception values
iex> {:ok, exception_val} = SnmpKit.SnmpLib.Types.coerce_value(:no_such_object, nil)
iex> exception_val
{:no_such_object, nil}Standards
RFC 1157 (SNMPv1), RFC 3416 (SNMPv2c operations), RFC 3412/3414/3826/7860 (SNMPv3 message processing, USM, AES, SHA-2 authentication) and ITU-T X.690 (BER).
Summary
Functions
@spec info() :: map()
Returns comprehensive information about the SnmpLib library capabilities.
Useful for debugging, configuration validation, and feature discovery.
Returns
A map containing:
:version: Library version:features: Available features and capabilities:modules: Core modules and their descriptions:compliance: RFC compliance information
Examples
info = SnmpKit.SnmpLib.info()
IO.puts("SNMP Library v" <> info.version)
IO.puts("Features: " <> Enum.join(info.features, ", "))
Returns the version of the SnmpLib library.
Examples
iex> is_binary(SnmpKit.SnmpLib.version())
true