Struct csnmp::client::Snmp2cClient
source · pub struct Snmp2cClient { /* private fields */ }Expand description
A SNMP2c client.
Implementations§
source§impl Snmp2cClient
impl Snmp2cClient
sourcepub async fn new(
target: SocketAddr,
community: Vec<u8>,
bind_addr: Option<SocketAddr>,
timeout: Option<Duration>
) -> Result<Self, SnmpClientError>
pub async fn new(
target: SocketAddr,
community: Vec<u8>,
bind_addr: Option<SocketAddr>,
timeout: Option<Duration>
) -> Result<Self, SnmpClientError>
Creates a new SNMP2c client.
sourcepub fn target(&self) -> SocketAddr
pub fn target(&self) -> SocketAddr
Returns the socket address of the target SNMP agent.
sourcepub fn set_target(
&mut self,
new_target: SocketAddr
) -> Result<(), SnmpClientError>
pub fn set_target(
&mut self,
new_target: SocketAddr
) -> Result<(), SnmpClientError>
Changes the socket address of the target SNMP agent.
Panics if the current target address has a different address family (e.g. due to a differing IP version) than the new target address.
sourcepub fn community(&self) -> &[u8] ⓘ
pub fn community(&self) -> &[u8] ⓘ
Returns a reference to the community string used to authenticate the communication.
sourcepub fn set_community(&mut self, new_community: Vec<u8>)
pub fn set_community(&mut self, new_community: Vec<u8>)
Changes the community string used to authenticate the communication.
sourcepub fn bind_addr(&self) -> Option<SocketAddr>
pub fn bind_addr(&self) -> Option<SocketAddr>
Returns the binding address used to create this SNMP client.
sourcepub fn timeout(&self) -> Option<Duration>
pub fn timeout(&self) -> Option<Duration>
Returns the duration that this SNMP client waits for a message to be sent or received before it gives up.
sourcepub fn set_timeout(&mut self, new_timeout: Option<Duration>)
pub fn set_timeout(&mut self, new_timeout: Option<Duration>)
Changes the duration that this SNMP client waits for a message to be sent or received before it gives up.
sourcepub async fn get(
&self,
oid: ObjectIdentifier
) -> Result<ObjectValue, SnmpClientError>
pub async fn get(
&self,
oid: ObjectIdentifier
) -> Result<ObjectValue, SnmpClientError>
Obtains the value for a single SNMP object.
sourcepub async fn get_next(
&self,
prev_oid: ObjectIdentifier
) -> Result<(ObjectIdentifier, ObjectValue), SnmpClientError>
pub async fn get_next(
&self,
prev_oid: ObjectIdentifier
) -> Result<(ObjectIdentifier, ObjectValue), SnmpClientError>
Obtains the value for the next object in the tree relative to the given OID. This is a
low-level operation, used as a building block for [walk].
sourcepub async fn get_bulk(
&self,
prev_oid: ObjectIdentifier,
non_repeaters: u32,
max_repetitions: u32
) -> Result<GetBulkResult, SnmpClientError>
pub async fn get_bulk(
&self,
prev_oid: ObjectIdentifier,
non_repeaters: u32,
max_repetitions: u32
) -> Result<GetBulkResult, SnmpClientError>
Obtains the values for the next objects in the tree relative to the given OID. This is a
low-level operation, used as a building block for [walk_bulk].
sourcepub async fn trap<B: Debug + Iterator<Item = (ObjectIdentifier, ObjectValue)>>(
&self,
bindings: B
) -> Result<(), SnmpClientError>
pub async fn trap<B: Debug + Iterator<Item = (ObjectIdentifier, ObjectValue)>>(
&self,
bindings: B
) -> Result<(), SnmpClientError>
Sends a trap message, informing a management station about one or more events.
sourcepub async fn inform<B: Debug + Iterator<Item = (ObjectIdentifier, ObjectValue)>>(
&self,
bindings: B
) -> Result<GetBulkResult, SnmpClientError>
pub async fn inform<B: Debug + Iterator<Item = (ObjectIdentifier, ObjectValue)>>(
&self,
bindings: B
) -> Result<GetBulkResult, SnmpClientError>
Sends an Inform message, informing a management station about one or more events. In contrast to a trap message, Inform messages incur a response.
sourcepub async fn walk(
&self,
top_oid: ObjectIdentifier
) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
pub async fn walk(
&self,
top_oid: ObjectIdentifier
) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
Walks an OID tree from the given OID, collecting and returning the results.
This is a high-level operation using [get] and [get_next] under the hood.
Unless the agent you are querying has issues with the Get-Bulk operation, using
[walk_bulk] is far more efficient.
sourcepub async fn walk_bulk(
&self,
top_oid: ObjectIdentifier,
non_repeaters: u32,
max_repetitions: u32
) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
pub async fn walk_bulk(
&self,
top_oid: ObjectIdentifier,
non_repeaters: u32,
max_repetitions: u32
) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
Walks an OID tree from the given OID, collecting and returning the results.
This is a high-level operation using [get] and [get_bulk] under the hood.
You can generally set non_repeaters to 0. Tune max_repetitions to your liking; 10 is a
good starting value.
Since [get_bulk] is functionally equivalent to [get_next] but fetches multiple values at
once, [walk_bulk] is more efficient than [walk]. However, some SNMP agents may be buggy
and provide different results to a [get_bulk] operation than to an equivalent sequence of
[get_next] operations. Therefore, [walk] is still provided.