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>,
retries: usize
) -> Result<Self, SnmpClientError>
pub async fn new( target: SocketAddr, community: Vec<u8>, bind_addr: Option<SocketAddr>, timeout: Option<Duration>, retries: usize ) -> 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 fn retries(&self) -> usize
pub fn retries(&self) -> usize
Returns the number of additional attempts to send the same message if the first attempt produces no reaction.
sourcepub fn set_retries(&mut self, new_retries: usize)
pub fn set_retries(&mut self, new_retries: usize)
Changes the number of additional attempts to send the same message if the first attempt produces no reaction.
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_multiple<I: IntoIterator<Item = ObjectIdentifier> + Debug>(
&self,
oids: I
) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
pub async fn get_multiple<I: IntoIterator<Item = ObjectIdentifier> + Debug>( &self, oids: I ) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
Obtains the value for multiple specified SNMP objects.
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,
oids: &[ObjectIdentifier],
non_repeaters: u32,
max_repetitions: u32
) -> Result<GetBulkResult, SnmpClientError>
pub async fn get_bulk( &self, oids: &[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
].
The non_repeaters
value declares how many OIDs in oids
will only return one value
instead of a subtree. These OIDs must be placed at the beginning of oids
. For example, you
may wish to simultaneously query sysUpTime
(single value) and ifName
(a whole subtree)
by passing them in this order in oids
and setting non_repeaters
to 1. Of course, it
makes little sense to set non_repeaters
to a higher value than there are OIDs in oids
.
The max_repetitions
value sets the maximum number of values to be returned in one
response. Agents may return fewer values if the full amount would not fit into an SNMP
response.
sourcepub async fn set(
&self,
oid: ObjectIdentifier,
value: ObjectValue
) -> Result<ObjectValue, SnmpClientError>
pub async fn set( &self, oid: ObjectIdentifier, value: ObjectValue ) -> Result<ObjectValue, SnmpClientError>
Sets the value for a single SNMP object.
sourcepub async fn set_multiple<I: IntoIterator<Item = (ObjectIdentifier, ObjectValue)> + Debug>(
&self,
oids_values: I
) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
pub async fn set_multiple<I: IntoIterator<Item = (ObjectIdentifier, ObjectValue)> + Debug>( &self, oids_values: I ) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
Sets the values for multiple specified SNMP objects.
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,
max_repetitions: u32
) -> Result<BTreeMap<ObjectIdentifier, ObjectValue>, SnmpClientError>
pub async fn walk_bulk( &self, top_oid: ObjectIdentifier, 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_bulk
] (and, optionally, [get
]) under the hood.
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.