SnmpKit.SnmpMgr.Config (snmpkit v0.6.3)

Configuration management for SnmpKit.SnmpMgr.

Provides global defaults and configuration options that can be set application-wide and used by all SNMP operations.

Summary

Functions

Adds a directory to the MIB search paths.

Returns a specification to start this module under a supervisor.

Gets configuration value with fallback to application config.

Gets all current configuration as a map.

Gets the default community string.

Gets the default port.

Gets the default number of retries.

Gets the default timeout.

Gets the default SNMP version.

Gets the current MIB search paths.

Merges the current configuration with provided opts, giving priority to opts.

Resets configuration to defaults.

Sets the default community string for SNMP requests.

Sets the default port for SNMP requests.

Sets the default number of retries for SNMP requests.

Sets the default timeout for SNMP requests in milliseconds.

Sets the default SNMP version.

Sets the MIB search paths (replaces existing paths).

Starts the configuration GenServer.

Functions

add_mib_path(path)

Adds a directory to the MIB search paths.

Examples

iex> SnmpKit.SnmpMgr.Config.add_mib_path("/usr/share/snmp/mibs")
:ok

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(key)

Gets configuration value with fallback to application config.

This is the main function used by other modules to get configuration values. It first checks the GenServer state, then falls back to application config, then to module defaults.

Examples

iex> SnmpKit.SnmpMgr.Config.get(:community)
"public"

iex> SnmpKit.SnmpMgr.Config.get(:timeout)
5000

get_all()

Gets all current configuration as a map.

Examples

iex> SnmpKit.SnmpMgr.Config.get_all()
%{
  community: "public",
  timeout: 5000,
  retries: 1,
  port: 161,
  version: :v1,
  mib_paths: []
}

get_default_community()

Gets the default community string.

Examples

iex> SnmpKit.SnmpMgr.Config.get_default_community()
"public"

get_default_port()

Gets the default port.

get_default_retries()

Gets the default number of retries.

get_default_timeout()

Gets the default timeout.

get_default_version()

Gets the default SNMP version.

get_mib_paths()

Gets the current MIB search paths.

merge_opts(opts)

Merges the current configuration with provided opts, giving priority to opts.

This is useful for functions that want to use global defaults but allow per-request overrides.

Examples

iex> SnmpKit.SnmpMgr.Config.merge_opts(community: "private", timeout: 10000)
[community: "private", timeout: 10000, retries: 1, port: 161]

reset()

Resets configuration to defaults.

Examples

iex> SnmpKit.SnmpMgr.Config.reset()
:ok

set_default_community(community)

Sets the default community string for SNMP requests.

Examples

iex> SnmpKit.SnmpMgr.Config.set_default_community("private")
:ok

set_default_port(port)

Sets the default port for SNMP requests.

Examples

iex> SnmpKit.SnmpMgr.Config.set_default_port(1161)
:ok

set_default_retries(retries)

Sets the default number of retries for SNMP requests.

Examples

iex> SnmpKit.SnmpMgr.Config.set_default_retries(3)
:ok

set_default_timeout(timeout)

Sets the default timeout for SNMP requests in milliseconds.

Examples

iex> SnmpKit.SnmpMgr.Config.set_default_timeout(10000)
:ok

set_default_version(version)

Sets the default SNMP version.

Examples

iex> SnmpKit.SnmpMgr.Config.set_default_version(:v2c)
:ok

set_mib_paths(paths)

Sets the MIB search paths (replaces existing paths).

Examples

iex> SnmpKit.SnmpMgr.Config.set_mib_paths(["/usr/share/snmp/mibs", "./mibs"])
:ok

start_link(opts \\ [])

Starts the configuration GenServer.