SnmpKit.SnmpMgr.Bulk (snmpkit v2.0.1)

Advanced SNMP bulk operations using GETBULK (SNMPv2c or SNMPv3).

This module provides efficient bulk operations that are significantly faster than iterative GETNEXT requests for retrieving large amounts of data.

Every function returns enriched varbind maps, see SnmpKit.SnmpMgr.Format.enriched_varbind/0.

Summary

Functions

Performs a single GETBULK request.

Optimized table retrieval using GETBULK.

Bulk walk operation using GETBULK instead of iterative GETNEXT.

Types

oid()

@type oid() :: SnmpKit.SnmpMgr.Core.oid()

target()

@type target() :: SnmpKit.SnmpMgr.Core.target()

varbind()

Functions

get_bulk(target, oid, opts \\ [])

@spec get_bulk(target(), oid() | [oid()], keyword()) ::
  {:ok, [varbind()]} | {:error, term()}

Performs a single GETBULK request.

GETBULK carries one starting OID per request here. A one-element list is accepted; a longer list returns {:error, {:unsupported, :multi_oid_get_bulk}} rather than silently dropping the extra OIDs.

Parameters

  • target - The target device
  • oid - Starting OID (or a one-element list)
  • opts - Options including :max_repetitions, :non_repeaters, :version (:v2c by default, :v3 honoured, :v1 rejected)

Examples

# Note: This function makes actual network calls and is not suitable for doctests
{:ok, results} = SnmpKit.SnmpMgr.Bulk.get_bulk("192.168.1.1", "ifTable", max_repetitions: 20)
# [
#   %{oid: "1.3.6.1.2.1.2.2.1.1.1", oid_list: [1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 1], name: "ifIndex.1",
#     type: :integer, value: 1, formatted: "1"},
#   %{oid: "1.3.6.1.2.1.2.2.1.1.2", oid_list: [1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 2], name: "ifIndex.2",
#     type: :integer, value: 2, formatted: "2"},
#   # ... up to 20 entries
# ]

Pass include_names: false, include_formatted: false for bare %{oid, oid_list, type, value} maps.

get_table_bulk(target, table_oid, opts \\ [])

@spec get_table_bulk(target(), oid(), keyword()) ::
  {:ok, [varbind()]} | {:error, term()}

Optimized table retrieval using GETBULK.

Uses GETBULK to efficiently retrieve an entire SNMP table, automatically handling pagination when tables are larger than max_repetitions.

Parameters

  • target - The target device
  • table_oid - The table OID to retrieve
  • opts - Options including :max_repetitions, :max_entries, :version

Examples

# Note: This function makes actual network calls and is not suitable for doctests
{:ok, results} = SnmpKit.SnmpMgr.Bulk.get_table_bulk("switch.local", "ifTable")
# [
#   %{oid: "1.3.6.1.2.1.2.2.1.2.1", oid_list: [...], name: "ifDescr.1",
#     type: :octet_string, value: "eth0", formatted: "eth0"},
#   %{oid: "1.3.6.1.2.1.2.2.1.3.1", oid_list: [...], name: "ifType.1",
#     type: :integer, value: 6, formatted: "ethernetCsmacd"},
#   # ...
# ]

walk_bulk(target, root_oid, opts \\ [])

@spec walk_bulk(target(), oid(), keyword()) :: {:ok, [varbind()]} | {:error, term()}

Bulk walk operation using GETBULK instead of iterative GETNEXT.

Significantly more efficient than traditional walks for large subtrees. The walk stops at the first endOfMibView/noSuchObject/noSuchInstance marker or OID outside root_oid, or when the agent stops making progress; the markers themselves are never part of the result.

Parameters

  • target - The target device
  • root_oid - Starting OID for the walk
  • opts - Options including :max_repetitions, :max_entries, :version

Examples

# Note: This function makes actual network calls and is not suitable for doctests
{:ok, results} = SnmpKit.SnmpMgr.Bulk.walk_bulk("device.local", "system")
# [
#   %{oid: "1.3.6.1.2.1.1.1.0", oid_list: [1, 3, 6, 1, 2, 1, 1, 1, 0], name: "sysDescr.0",
#     type: :octet_string, value: "System Description", formatted: "System Description"},
#   %{oid: "1.3.6.1.2.1.1.3.0", oid_list: [1, 3, 6, 1, 2, 1, 1, 3, 0], name: "sysUpTime.0",
#     type: :timeticks, value: 12345, formatted: "2 minutes 3 seconds"},
#   # ...
# ]