Struct csnmp::client::Snmp2cClient

source ·
pub struct Snmp2cClient { /* private fields */ }
Expand description

A SNMP2c client.

Implementations§

source§

impl Snmp2cClient

source

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.

source

pub fn target(&self) -> SocketAddr

Returns the socket address of the target SNMP agent.

source

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.

source

pub fn community(&self) -> &[u8]

Returns a reference to the community string used to authenticate the communication.

source

pub fn set_community(&mut self, new_community: Vec<u8>)

Changes the community string used to authenticate the communication.

source

pub fn bind_addr(&self) -> Option<SocketAddr>

Returns the binding address used to create this SNMP client.

source

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.

source

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.

source

pub fn retries(&self) -> usize

Returns the number of additional attempts to send the same message if the first attempt produces no reaction.

source

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.

source

pub async fn get( &self, oid: ObjectIdentifier ) -> Result<ObjectValue, SnmpClientError>

Obtains the value for a single SNMP object.

source

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.

source

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].

source

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.

source

pub async fn set( &self, oid: ObjectIdentifier, value: ObjectValue ) -> Result<ObjectValue, SnmpClientError>

Sets the value for a single SNMP object.

source

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.

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl Debug for Snmp2cClient

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.