Search documentation of snmpkit

# SnmpKit.SnmpLib.PDU.Builder (snmpkit v1.3.17)

High-level PDU and message building functions for SNMP operations.

This module provides functions to build various types of SNMP PDUs and messages, including GET, GETNEXT, SET, GETBULK requests, and responses.

# Summary

## Types

error_status()
message()
oid()
pdu()
pdu_type()
snmp_value()
snmp_version()
varbind()

## Functions

build_get_bulk_request(oid_list, request_id, non_repeaters \\ 0, max_repetitions \\ 10)

Builds a GETBULK request PDU for SNMPv2c.

build_get_next_request(oid_list, request_id)

Builds a GETNEXT request PDU.

build_get_request(oid_list, request_id)

Builds a GET request PDU.

build_get_request_multi(varbinds, request_id)

Builds a GET request PDU with multiple varbinds.

build_message(pdu, community, version \\ :v1)

Builds an SNMP message structure.

build_response(request_id, error_status, error_index, varbinds \\ [])

Builds a response PDU.

build_set_request(oid_list, arg, request_id)

Builds a SET request PDU.

create_error_response(request_pdu, error_status, error_index \\ 0)

Creates an error response PDU from a request PDU.

validate(pdu)

Validates a PDU structure.

validate_community(encoded_message, expected_community)

Validates a community string against an encoded SNMP message.

# Types

# error_status()

    @type error_status() :: SnmpKit.SnmpLib.PDU.Constants.error_status()

# message()

    @type message() :: SnmpKit.SnmpLib.PDU.Constants.message()

# oid()

    @type oid() :: SnmpKit.SnmpLib.PDU.Constants.oid()

# pdu()

    @type pdu() :: SnmpKit.SnmpLib.PDU.Constants.pdu()

# pdu_type()

    @type pdu_type() :: SnmpKit.SnmpLib.PDU.Constants.pdu_type()

# snmp_value()

    @type snmp_value() :: SnmpKit.SnmpLib.PDU.Constants.snmp_value()

# snmp_version()

    @type snmp_version() :: SnmpKit.SnmpLib.PDU.Constants.snmp_version()

# varbind()

    @type varbind() :: SnmpKit.SnmpLib.PDU.Constants.varbind()

# Functions

# build_get_bulk_request(oid_list, request_id, non_repeaters \\ 0, max_repetitions \\ 10)

    @spec build_get_bulk_request(
      oid(),
      non_neg_integer(),
      non_neg_integer(),
      non_neg_integer()
    ) :: pdu()

Builds a GETBULK request PDU for SNMPv2c.

## Parameters

- `oid_list`: Starting OID
- `request_id`: Request identifier
- `non_repeaters`: Number of non-repeating variables (default: 0)
- `max_repetitions`: Maximum repetitions (default: 10)

# build_get_next_request(oid_list, request_id)

    @spec build_get_next_request(oid(), non_neg_integer()) :: pdu()

Builds a GETNEXT request PDU.

# build_get_request(oid_list, request_id)

    @spec build_get_request(oid(), non_neg_integer()) :: pdu()

Builds a GET request PDU.

# build_get_request_multi(varbinds, request_id)

    @spec build_get_request_multi([varbind()], non_neg_integer()) :: pdu()

Builds a GET request PDU with multiple varbinds.

# build_message(pdu, community, version \\ :v1)

    @spec build_message(pdu(), binary(), snmp_version()) :: message()

Builds an SNMP message structure.

## Parameters

- `pdu`: The PDU to include in the message
- `community`: Community string
- `version`: SNMP version (:v1, :v2c, etc.)

# build_response(request_id, error_status, error_index, varbinds \\ [])

    @spec build_response(non_neg_integer(), error_status(), non_neg_integer(), [varbind()]) ::
      pdu()

Builds a response PDU.

# build_set_request(oid_list, arg, request_id)

    @spec build_set_request(oid(), {atom(), any()}, non_neg_integer()) :: pdu()

Builds a SET request PDU.

# create_error_response(request_pdu, error_status, error_index \\ 0)

    @spec create_error_response(pdu(), error_status(), non_neg_integer()) :: pdu()

Creates an error response PDU from a request PDU.

## Examples

    error_pdu = SnmpKit.SnmpLib.PDU.Builder.create_error_response(request_pdu, 2, 1)

# validate(pdu)

    @spec validate(pdu()) :: {:ok, pdu()} | {:error, atom()}

Validates a PDU structure.

# validate_community(encoded_message, expected_community)

    @spec validate_community(binary(), binary()) :: :ok | {:error, atom()}

Validates a community string against an encoded SNMP message.