snmp_ex v0.4.0 SNMP
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
Link to this type
req_params()
req_params() :: %{ uri: URI.t(), credential: credential(), varbinds: [req_varbind(), ...] }
Link to this type
req_varbind()
Link to this type
snmp_credential()
snmp_credential() :: SNMP.CommunityCredential.t() | SNMP.USMCredential.t()
Link to this type
varbind()
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
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)
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
request(map, options \\ [])
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"
}
]
}
Link to this function
resolve_object_name_to_oid(oid)
Link to this function
start()
Link to this function
start(type, args)
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]
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],
}
]