snmp_ex v0.2.2 SNMP

An SNMP client library for Elixir.

Link to this section Summary

Functions

Returns a keyword list containing the given SNMPv1/2c/3 credentials

Returns a keyword list containing the given SNMPv1/2c community

Returns a keyword list containing the given SNMPv3 noAuthNoPriv credentials

Returns a keyword list containing the given SNMPv3 authNoPriv credentials

Converts oid to dot-delimited string

Called when an application is started

Converts dot-delimited oid string to list

Link to this section Types

Link to this type

mib_name()
mib_name() :: String.t()

Link to this type

snmp_credential()

Link to this section Functions

Link to this function

credential(args)
credential([atom() | String.t()]) :: snmp_credential() | no_return()

Returns a keyword list containing the given SNMPv1/2c/3 credentials.

Example

iex> SNMP.credential([:v1, "public"])
%SNMP.CommunityCredential{version: :v1, sec_model: :v1, community: 'public'}

iex> SNMP.credential([:v2c, "public"])
%SNMP.CommunityCredential{version: :v2, sec_model: :v2c, community: 'public'}

iex> SNMP.credential([:v3, :no_auth_no_priv, "user"])
%SNMP.USMCredential{sec_level: :noAuthNoPriv, sec_name:  'user'}

iex> SNMP.credential([:v3, :auth_no_priv, "user", :md5, "authpass"])
%SNMP.USMCredential{
  sec_level: :authNoPriv,
  sec_name:  'user',
  auth:      :md5,
  auth_pass: 'authpass',
}

iex> SNMP.credential([:v3, :auth_no_priv, "user", :sha, "authpass"])
%SNMP.USMCredential{
  sec_level: :authNoPriv,
  sec_name:  'user',
  auth:      :sha,
  auth_pass: 'authpass',
}

iex> SNMP.credential([:v3, :auth_priv, "user", :md5, "authpass", :des, "privpass"])
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :md5,
  auth_pass: 'authpass',
  priv:      :des,
  priv_pass: 'privpass',
}

iex> SNMP.credential([:v3, :auth_priv, "user", :sha, "authpass", :des, "privpass"])
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :sha,
  auth_pass: 'authpass',
  priv:      :des,
  priv_pass: 'privpass',
}

iex> SNMP.credential([:v3, :auth_priv, "user", :md5, "authpass", :aes, "privpass"])
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :md5,
  auth_pass: 'authpass',
  priv:      :aes,
  priv_pass: 'privpass',
}

iex> SNMP.credential([:v3, :auth_priv, "user", :sha, "authpass", :aes, "privpass"])
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :sha,
  auth_pass: 'authpass',
  priv:      :aes,
  priv_pass: 'privpass',
}
Link to this function

credential(version, community)
credential(:v1 | :v2c, String.t()) :: snmp_credential() | no_return()

Returns a keyword list containing the given SNMPv1/2c community.

Example

iex> SNMP.credential(:v1, "public")
%SNMP.CommunityCredential{version: :v1, sec_model: :v1, community: 'public'}

iex> SNMP.credential(:v2c, "public")
%SNMP.CommunityCredential{version: :v2, sec_model: :v2c, community: 'public'}
Link to this function

credential(version, sec_level, sec_name)
credential(:v3, :no_auth_no_priv, String.t()) :: snmp_credential() | no_return()

Returns a keyword list containing the given SNMPv3 noAuthNoPriv credentials.

Example

iex> SNMP.credential(:v3, :no_auth_no_priv, "user")
%SNMP.USMCredential{sec_level: :noAuthNoPriv, sec_name: 'user'}
Link to this function

credential(version, sec_level, sec_name, auth_proto, auth_pass)
credential(:v3, :auth_no_priv, String.t(), :md5 | :sha, String.t()) ::
  snmp_credential() | no_return()

Returns a keyword list containing the given SNMPv3 authNoPriv credentials.

Example

iex> SNMP.credential(:v3, :auth_no_priv, "user", :md5, "authpass")
%SNMP.USMCredential{
  sec_level: :authNoPriv,
  sec_name:  'user',
  auth:      :md5,
  auth_pass: 'authpass',
}

iex> SNMP.credential(:v3, :auth_no_priv, "user", :sha, "authpass")
%SNMP.USMCredential{
  sec_level: :authNoPriv,
  sec_name:  'user',
  auth:      :sha,
  auth_pass: 'authpass',
}
Link to this function

credential(version, sec_level, sec_name, auth_proto, auth_pass, priv_proto, priv_pass)
credential(
  :v3,
  :auth_priv,
  String.t(),
  :md5 | :sha,
  String.t(),
  :des | :aes,
  String.t()
) :: snmp_credential() | no_return()

Returns snmp_credential/0 containing the given SNMPv3 authPriv credentials.

Examples

iex> SNMP.credential(:v3, :auth_priv, "user", :md5, "authpass", :des, "privpass")
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :md5,
  auth_pass: 'authpass',
  priv:      :des,
  priv_pass: 'privpass',
}

iex> SNMP.credential(:v3, :auth_priv, "user", :sha, "authpass", :des, "privpass")
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :sha,
  auth_pass: 'authpass',
  priv:      :des,
  priv_pass: 'privpass',
}

iex> SNMP.credential(:v3, :auth_priv, "user", :md5, "authpass", :aes, "privpass")
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :md5,
  auth_pass: 'authpass',
  priv:      :aes,
  priv_pass: 'privpass',
}

iex> SNMP.credential(:v3, :auth_priv, "user", :sha, "authpass", :aes, "privpass")
%SNMP.USMCredential{
  sec_level: :authPriv,
  sec_name:  'user',
  auth:      :sha,
  auth_pass: 'authpass',
  priv:      :aes,
  priv_pass: 'privpass',
}
Link to this function

get(objects, agent, credential, options \\ [])

Link to this function

get_next(objects, agent, credential, options \\ [])

Link to this function

list_oid_to_string(oid)
list_oid_to_string([non_neg_integer()]) :: String.t() | no_return()

Converts oid to dot-delimited string.

Example

iex> SNMP.list_oid_to_string([1,3,6,1,2,1,1,5,0])
"1.3.6.1.2.1.1.5.0"
Link to this function

load_mib(mib_name)
load_mib(mib_name()) :: :ok | {:error, term()}

Link to this function

load_mib!(mib_name)
load_mib!(mib_name()) :: :ok | no_return()

Link to this function

resolve_object_name_to_oid(oid)

Link to this function

set(objects, agent, credential, value, value_type, options \\ [])

Link to this function

start(type, args)

Called when an application is started.

This function is called when an application is started using Application.start/2 (and functions on top of that, such as Application.ensure_started/2). This function should start the top-level process of the application (which should be the top supervisor of the application's supervision tree if the application follows the OTP design principles around supervision).

start_type defines how the application is started:

  • :normal - used if the startup is a normal startup or if the application is distributed and is started on the current node because of a failover from another node and the application specification key :start_phases is :undefined.
  • {:takeover, node} - used if the application is distributed and is started on the current node because of a failover on the node node.
  • {:failover, node} - used if the application is distributed and is started on the current node because of a failover on node node, and the application specification key :start_phases is not :undefined.

start_args are the arguments passed to the application in the :mod specification key (e.g., mod: {MyApp, [:my_args]}).

This function should either return {:ok, pid} or {:ok, pid, state} if startup is successful. pid should be the PID of the top supervisor. state can be an arbitrary term, and if omitted will default to []; if the application is later stopped, state is passed to the stop/1 callback (see the documentation for the c:stop/1 callback for more information).

use Application provides no default implementation for the start/2 callback.

Callback implementation for Application.start/2.

Link to this function

string_oid_to_list(oid)
string_oid_to_list(String.t()) :: [non_neg_integer()] | no_return()

Converts dot-delimited oid string to list.

Example

iex> SNMP.string_oid_to_list("1.3.6.1.2.1.1.5.0")
[1,3,6,1,2,1,1,5,0]
Link to this function

walk(object, agent, credential, options \\ [])