Search documentation of snmpkit

# SnmpKit.SnmpMgr.Core (snmpkit v1.3.17)

Core SNMP operations using Erlang's SNMP PDU functions directly.

This module handles the low-level SNMP PDU encoding/decoding and UDP communication without requiring the heavyweight :snmpm manager process.

## Timeout Behavior

All functions in this module use a single timeout parameter that controls the SNMP PDU timeout - how long to wait for a response to each individual SNMP packet sent to the target device.

- Default timeout: 10 seconds (10,000 milliseconds)
- Timeout applies to: Each individual SNMP PDU (GET, SET, GETBULK, etc.)
- Not applicable to: Multi-PDU operations (use walk functions for those)

For operations that may require multiple PDUs (like walking large tables), consider using the higher-level walk functions in `SnmpKit.SnmpMgr.MultiV2` which handle multi-PDU timeouts appropriately.

# Summary

## Types

oid()
opts()
snmp_result()
target()

## Functions

parse_oid(oid)

Parses and normalizes an OID to internal list format.

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

Sends an SNMP GETBULK request (SNMPv2c only).

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

Sends an asynchronous SNMP GETBULK request.

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

Sends a GETNEXT request to retrieve the next OID in the MIB tree.

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

Sends an SNMP GET request and returns the response.

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

Sends an asynchronous SNMP GET request.

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

Sends a GET request and returns the result in 3-tuple format.

send_set_request(target, oid, value, opts \\ [])

Sends an SNMP SET request and returns the response.

# Types

# oid()

    @type oid() :: binary() | [non_neg_integer()]

# opts()

    @type opts() :: keyword()

# snmp_result()

    @type snmp_result() :: {:ok, term()} | {:error, atom() | tuple()}

# target()

    @type target() :: binary() | tuple() | map()

# Functions

# parse_oid(oid)

    @spec parse_oid(oid()) :: {:ok, [non_neg_integer()]} | {:error, term()}

Parses and normalizes an OID to internal list format.

Converts external OID input (string or list) to internal list of integers format. This function establishes the API boundary - all external input is converted to internal list format here.

# send_get_bulk_request(target, oid, opts \\ [])

    @spec send_get_bulk_request(target(), oid(), opts()) :: snmp_result()

Sends an SNMP GETBULK request (SNMPv2c only).

GETBULK is more efficient than multiple GETNEXT operations for retrieving multiple consecutive OIDs.

## Parameters

- `target` - SNMP target (host, "host:port", or target map)
- `oid` - Starting OID for bulk retrieval
- `opts` - Request options
  - `:timeout` - SNMP PDU timeout in milliseconds (default: 10000)
  - `:max_repetitions` - Maximum number of OIDs to retrieve (default: 30)
  - `:community` - SNMP community string (default: "public")
  - `:version` - SNMP version (must be :v2c) (default: :v2c)

# send_get_bulk_request_async(target, oid, opts \\ [])

    @spec send_get_bulk_request_async(target(), oid(), opts()) :: reference()

Sends an asynchronous SNMP GETBULK request.

Returns immediately with a reference. The calling process will receive a message with the result.

## Parameters

- `target` - SNMP target (host, "host:port", or target map)
- `oid` - Starting OID for bulk retrieval
- `opts` - Request options
  - `:timeout` - SNMP PDU timeout in milliseconds (default: 10000)
  - `:max_repetitions` - Maximum number of OIDs to retrieve (default: 30)
  - `:community` - SNMP community string (default: "public")
  - `:version` - SNMP version (must be :v2c) (default: :v2c)

## Returns

Reference that will be included in the response message.

# send_get_next_request(target, oid, opts \\ [])

    @spec send_get_next_request(target(), oid(), opts()) :: snmp_result()

Sends a GETNEXT request to retrieve the next OID in the MIB tree.

Now uses the proper SnmpKit.SnmpLib.Manager.get_next/3 function which handles version-specific logic (GETNEXT for v1, GETBULK for v2c+) correctly.

# send_get_request(target, oid, opts \\ [])

    @spec send_get_request(target(), oid(), opts()) :: snmp_result()

Sends an SNMP GET request and returns the response.

## Parameters

- `target` - SNMP target (host, "host:port", or target map)
- `oid` - Object identifier (string or list format)
- `opts` - Request options
  - `:timeout` - SNMP PDU timeout in milliseconds (default: 10000)
  - `:community` - SNMP community string (default: "public")
  - `:version` - SNMP version (:v1, :v2c) (default: :v2c)
  - `:port` - SNMP port (default: 161)

# send_get_request_async(target, oid, opts \\ [])

    @spec send_get_request_async(target(), oid(), opts()) :: reference()

Sends an asynchronous SNMP GET request.

Returns immediately with a reference. The calling process will receive a message with the result.

## Parameters

- `target` - SNMP target (host, "host:port", or target map)
- `oid` - Object identifier (string or list format)
- `opts` - Request options
  - `:timeout` - SNMP PDU timeout in milliseconds (default: 10000)
  - `:community` - SNMP community string (default: "public")
  - `:version` - SNMP version (:v1, :v2c) (default: :v2c)

## Returns

Reference that will be included in the response message.

# send_get_request_with_type(target, oid, opts \\ [])

    @spec send_get_request_with_type(target(), oid(), opts()) ::
      {:ok, {String.t(), atom(), any()}} | {:error, any()}

Sends a GET request and returns the result in 3-tuple format.

This function returns `{oid_string, type, value}` for consistency with other operations like walk, bulk, etc.

# send_set_request(target, oid, value, opts \\ [])

    @spec send_set_request(target(), oid(), term(), opts()) :: snmp_result()

Sends an SNMP SET request and returns the response.

## Parameters

- `target` - SNMP target (host, "host:port", or target map)
- `oid` - Object identifier to set
- `value` - Value to set (will be encoded based on type)
- `opts` - Request options
  - `:timeout` - SNMP PDU timeout in milliseconds (default: 10000)
  - `:community` - SNMP community string (default: "public")
  - `:version` - SNMP version (:v1, :v2c) (default: :v2c)