SnmpKit.SnmpLib (snmpkit v2.0.1)

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

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

Returns comprehensive information about the SnmpLib library capabilities.

Returns the version of the SnmpLib library.

Functions

info()

@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, ", "))

version()

Returns the version of the SnmpLib library.

Examples

iex> is_binary(SnmpKit.SnmpLib.version())
true