SNMP (snmp_ex v0.7.0)
An SNMP client library for Elixir.
Summary
Functions
Performs a SNMP BULKWALK operation, efficiently retrieving a subtree of MIB objects.
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.
Types
asn1_type()
asn1_value()
@type asn1_value() :: any()
credential()
@type credential() :: map()
mib_name()
@type mib_name() :: String.t()
object_id()
@type object_id() :: object_name() | [non_neg_integer(), ...]
object_name()
req_options()
@type req_options() :: Keyword.t()
req_params()
@type req_params() :: %{ uri: URI.t(), credential: credential(), varbinds: [req_varbind(), ...] }
req_varbind()
request_result()
snmp_credential()
@type snmp_credential() :: SNMP.CommunityCredential.t() | SNMP.USMCredential.t()
varbind()
@type varbind() :: %{oid: object_id(), type: asn1_type(), value: asn1_value()}
Functions
bulkwalk(request, options \\ [])
@spec bulkwalk(req_params(), req_options()) :: Enumerable.t()
Performs a SNMP BULKWALK operation, efficiently retrieving a subtree of MIB objects.
Parameters
- request: Map containing uri, credential, and varbinds
- options: Keyword list of options including max_repetitions and timeout
Returns
- List of varbinds in the requested subtree
credential(map)
Returns a keyword list containing the given SNMP credentials.
Example
iex> SNMP.credential(%{community: "public"})
%SNMP.CommunityCredential{version: :v1, sec_model: :v1, community: ~c"public"}
iex> SNMP.credential(
...> %{version: :v2, community: "public"}
...> )
%SNMP.CommunityCredential{version: :v2, sec_model: :v2c, community: ~c"public"}
iex> SNMP.credential(%{sec_name: "user"})
%SNMP.USMCredential{
version: :v3,
sec_model: :usm,
sec_level: :noAuthNoPriv,
sec_name: ~c"user",
auth: :usmNoAuthProtocol,
auth_pass: nil,
priv: :usmNoPrivProtocol,
priv_pass: nil
}
iex> SNMP.credential(
...> %{sec_name: "user",
...> auth: :sha,
...> auth_pass: "authpass",
...> }
...> )
%SNMP.USMCredential{
version: :v3,
sec_model: :usm,
sec_level: :authNoPriv,
sec_name: ~c"user",
auth: :usmHMACSHAAuthProtocol,
auth_pass: ~c"authpass",
priv: :usmNoPrivProtocol,
priv_pass: nil
}
iex> SNMP.credential(
...> %{sec_name: "user",
...> auth: :sha,
...> auth_pass: "authpass",
...> priv: :aes,
...> priv_pass: "privpass",
...> }
...> )
%SNMP.USMCredential{
version: :v3,
sec_model: :usm,
sec_level: :authPriv,
sec_name: ~c"user",
auth: :usmHMACSHAAuthProtocol,
auth_pass: ~c"authpass",
priv: :usmAesCfb128Protocol,
priv_pass: ~c"privpass"
}
list_oid_to_string(oid)
@spec 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"
load_mib(mib_name)
request(map, options \\ [])
@spec request(req_params(), req_options()) :: request_result()
Perform an SNMP GET/SET request.
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"
}
]
}
resolve_object_name_to_oid(oid)
start()
start(type, args)
Callback implementation for Application.start/2
.
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
iex> SNMP.string_oid_to_list("1.3.6.1.2.1.1.5.0")
[1,3,6,1,2,1,1,5,0]
sync_get(target, oids, timeout)
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
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],
}
]