SNMP (snmp_ex v0.4.2)

An SNMP client library for Elixir.

Link to this section Summary

Functions

Returns a keyword list containing the given SNMP credentials.

Converts oid to dot-delimited string.

Perform an SNMP GET/SET request.

Callback implementation for Application.start/2.

Converts dot-delimited oid string to list.

Perform an SNMP walk using GETNEXT operations.

Link to this section Types

@type asn1_type() :: atom() | binary()
Link to this type

asn1_value()

@type asn1_value() :: any()
Link to this type

credential()

@type credential() :: map()
@type mib_name() :: String.t()
@type object_id() :: object_name() | [non_neg_integer(), ...]
Link to this type

object_name()

@type object_name() :: binary() | atom()
Link to this type

req_options()

@type req_options() :: Keyword.t()
Link to this type

req_params()

@type req_params() :: %{
  uri: URI.t(),
  credential: credential(),
  varbinds: [req_varbind(), ...]
}
Link to this type

req_varbind()

@type req_varbind() ::
  %{oid: object_id()}
  | %{oid: object_id(), type: asn1_type()}
  | %{oid: object_id(), type: asn1_type(), value: asn1_value()}
Link to this type

request_result()

@type request_result() :: {:ok, [varbind(), ...]} | {:error, any()}
Link to this type

snmp_credential()

@type snmp_credential() :: SNMP.CommunityCredential.t() | SNMP.USMCredential.t()
@type varbind() :: %{oid: object_id(), type: asn1_type(), value: asn1_value()}

Link to this section Functions

Link to this function

credential(map)

Returns a keyword list containing the given SNMP credentials.

example

Example

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

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

iex> SNMP.credential(%{sec_name: "user"})
%SNMP.USMCredential{sec_name: 'user'}

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

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

list_oid_to_string(oid)

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

Converts oid to dot-delimited string.

example

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)

@spec load_mib(mib_name()) :: :ok | {:error, term()}
Link to this function

request(map, options \\ [])

@spec request(req_params(), req_options()) :: request_result()

Perform an SNMP GET/SET request.

example

Example

iex> %{uri: URI.parse("snmp://an-snmp-host.local"),
...>   credential: v2_cred,
...>   varbinds: [%{oid: [1,3,6,1,2,1,1,5,0]}],
...> } |> SNMP.request
{ :ok,
  [ %{oid: [1, 3, 6, 1, 2, 1, 1, 5, 0],
      type: :"OCTET STRING",
      value: "an-snmp-host"
    }
  ]
}

iex> %{uri: URI.parse("snmp://an-snmp-host.local"),
...>   credential: v2_cred,
...>   varbinds: [
...>     %{oid: [1,3,6,1,2,1,1,5,0],
...>       type: :s,
...>       value: "new-hostname",
...>     },
...>   ],
...> } |> SNMP.request
{ :ok,
  [ %{oid: [1, 3, 6, 1, 2, 1, 1, 5, 0],
      type: :"OCTET STRING",
      value: "new-hostname"
    }
  ]
}
Link to this function

resolve_object_name_to_oid(oid)

@spec resolve_object_name_to_oid(object_id()) ::
  {:ok, object_id()} | {:error, term()} | no_return()
Link to this function

start(type, args)

Callback implementation for Application.start/2.

Link to this function

string_oid_to_list(oid)

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

Converts dot-delimited oid string to list.

example

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

sync_get(target, oids, timeout)

Link to this function

walk(map, options \\ [])

@spec walk(req_params(), req_options()) :: Enumerable.t()

Perform an SNMP walk using GETNEXT operations.

This function returns a stream, which ensures that the resulting walk is bounded.

example

Example

iex> %{uri: URI.parse("snmp://an-snmp-host.local"),
...>   credential: v3_cred,
...>   varbinds: [%{oid: "ipAddrTable"}],
...> } |> SNMP.walk
...> |> Enum.take(1)
[ %{oid: [1, 3, 6, 1, 2, 1, 4, 20, 1, 1, 192, 0, 2, 1],
    type: :IpAddress,
    value: [192, 0, 2, 1],
  }
]