Search documentation of snmpkit

# SnmpKit.SnmpSim.Device (snmpkit v1.2.0)

Lightweight Device GenServer for handling SNMP requests. Uses shared profiles and minimal device-specific state for scalability.

Features:

- Dynamic value generation with realistic patterns
- Shared profile system for memory efficiency
- Counter and gauge simulation with proper incrementing
- Comprehensive error handling and fallback mechanisms
- Support for SNMP walk operations

# Summary

## Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

cleanup_all_devices()

Cleanup all orphaned SNMP simulator device processes. Useful for test cleanup when devices may have been left running.

get(device_pid, oid)

Get an OID value from the device (for testing).

get_bulk(device_pid, oids, max_repetitions)

Get bulk OID values from the device (for testing).

get_bulk(device_pid, oids, non_repeaters, max_repetitions)
get_info(device_pid)

Get device information and statistics.

get_next(device_pid, oid)

Get the next OID value from the device (for testing).

monitor_device(device_pid)

Monitor a device process and get notified when it dies. Returns a monitor reference that can be used with Process.demonitor/1.

reboot(device_pid)

Simulate a device reboot.

set_gauge(device_pid, oid, value)

Set a gauge value manually (useful for testing).

start_link(device_config)

Start a device with the given device configuration.

start_link_monitored(device_config)

Create a device with monitoring enabled. Returns {:ok, {device_pid, monitor_ref}} or {:error, reason}.

stop(device_pid)

Stop a device gracefully with resilient error handling.

update_counter(device_pid, oid, increment)

Update device counters manually (useful for testing).

walk(device_pid, oid)

Walk OID values from the device (for testing).

# Functions

# child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# cleanup_all_devices()

Cleanup all orphaned SNMP simulator device processes. Useful for test cleanup when devices may have been left running.

# get(device_pid, oid)

Get an OID value from the device (for testing).

# get_bulk(device_pid, oids, max_repetitions)

Get bulk OID values from the device (for testing).

# get_bulk(device_pid, oids, non_repeaters, max_repetitions)

# get_info(device_pid)

Get device information and statistics.

# get_next(device_pid, oid)

Get the next OID value from the device (for testing).

# monitor_device(device_pid)

Monitor a device process and get notified when it dies. Returns a monitor reference that can be used with Process.demonitor/1.

# reboot(device_pid)

Simulate a device reboot.

# set_gauge(device_pid, oid, value)

Set a gauge value manually (useful for testing).

# start_link(device_config)

Start a device with the given device configuration.

## Device Config

Device config should contain:

- `:port` - UDP port for the device (required)
- `:device_type` - Type of device (:cable_modem, :switch, etc.)
- `:device_id` - Unique device identifier
- `:community` - SNMP community string (default: "public")
- `:mac_address` - MAC address (auto-generated if not provided)

## Examples

    device_config = %{
      port: 9001,
      device_type: :cable_modem,
      device_id: "cable_modem_9001",
      community: "public"
    }

    {:ok, device} = SnmpKit.SnmpSim.Device.start_link(device_config)

# start_link_monitored(device_config)

Create a device with monitoring enabled. Returns {:ok, {device_pid, monitor_ref}} or {:error, reason}.

# stop(device_pid)

Stop a device gracefully with resilient error handling.

# update_counter(device_pid, oid, increment)

Update device counters manually (useful for testing).

# walk(device_pid, oid)

Walk OID values from the device (for testing).