pub struct Client<T: Transport = UdpTransport> { /* private fields */ }Expand description
SNMP client.
Generic over transport type, with UdpTransport as default.
Implementations§
Source§impl Client<UdpTransport>
impl Client<UdpTransport>
Sourcepub fn builder(
target: impl Into<String>,
auth: impl Into<Auth>,
) -> ClientBuilder
pub fn builder( target: impl Into<String>, auth: impl Into<Auth>, ) -> ClientBuilder
Create a new SNMP client builder.
This is the single entry point for client construction, supporting all
SNMP versions (v1, v2c, v3) through the Auth enum.
§Example
use async_snmp::{Auth, Client};
use std::time::Duration;
// Simple v2c client with default settings
let client = Client::builder("192.168.1.1:161", Auth::v2c("public"))
.connect().await?;
// v3 client with authentication
let client = Client::builder("192.168.1.1:161",
Auth::usm("admin").auth(async_snmp::v3::AuthProtocol::Sha256, "password"))
.timeout(Duration::from_secs(10))
.retries(5)
.connect().await?;Source§impl<T: Transport> Client<T>
impl<T: Transport> Client<T>
Sourcepub fn new(transport: T, config: ClientConfig) -> Self
pub fn new(transport: T, config: ClientConfig) -> Self
Create a new client with the given transport and config.
Sourcepub fn with_engine_cache(
transport: T,
config: ClientConfig,
engine_cache: Arc<EngineCache>,
) -> Self
pub fn with_engine_cache( transport: T, config: ClientConfig, engine_cache: Arc<EngineCache>, ) -> Self
Create a new V3 client with a shared engine cache.
Sourcepub fn peer_addr(&self) -> SocketAddr
pub fn peer_addr(&self) -> SocketAddr
Get the peer (target) address.
Returns the remote address that this client sends requests to.
Named to match std::net::TcpStream::peer_addr().
Sourcepub async fn get_many(&self, oids: &[Oid]) -> Result<Vec<VarBind>>
pub async fn get_many(&self, oids: &[Oid]) -> Result<Vec<VarBind>>
GET multiple OIDs.
If the OID list exceeds max_oids_per_request, the request is
automatically split into multiple batches. Results are returned
in the same order as the input OIDs.
§Example
let results = client.get_many(&[
oid!(1, 3, 6, 1, 2, 1, 1, 1, 0), // sysDescr
oid!(1, 3, 6, 1, 2, 1, 1, 3, 0), // sysUpTime
oid!(1, 3, 6, 1, 2, 1, 1, 5, 0), // sysName
]).await?;Sourcepub async fn get_next_many(&self, oids: &[Oid]) -> Result<Vec<VarBind>>
pub async fn get_next_many(&self, oids: &[Oid]) -> Result<Vec<VarBind>>
GETNEXT for multiple OIDs.
If the OID list exceeds max_oids_per_request, the request is
automatically split into multiple batches. Results are returned
in the same order as the input OIDs.
§Example
let results = client.get_next_many(&[
oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2), // ifDescr
oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 3), // ifType
]).await?;Sourcepub async fn set_many(&self, varbinds: &[(Oid, Value)]) -> Result<Vec<VarBind>>
pub async fn set_many(&self, varbinds: &[(Oid, Value)]) -> Result<Vec<VarBind>>
SET multiple OIDs.
If the varbind list exceeds max_oids_per_request, the request is
automatically split into multiple batches. Results are returned
in the same order as the input varbinds.
§Example
let results = client.set_many(&[
(oid!(1, 3, 6, 1, 2, 1, 1, 5, 0), Value::from("new-hostname")),
(oid!(1, 3, 6, 1, 2, 1, 1, 6, 0), Value::from("new-location")),
]).await?;Sourcepub async fn get_bulk(
&self,
oids: &[Oid],
non_repeaters: i32,
max_repetitions: i32,
) -> Result<Vec<VarBind>>
pub async fn get_bulk( &self, oids: &[Oid], non_repeaters: i32, max_repetitions: i32, ) -> Result<Vec<VarBind>>
GETBULK request (SNMPv2c/v3 only).
Retrieves multiple variable bindings in a single request.
§Arguments
oids- OIDs to retrievenon_repeaters- Number of OIDs to treat as non-repeatingmax_repetitions- Maximum iterations for repeating OIDs
§Example
// Get next 10 entries starting from ifDescr
let results = client.get_bulk(&[oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2)], 0, 10).await?;
for vb in results {
println!("{}: {:?}", vb.oid, vb.value);
}Sourcepub fn walk(&self, oid: Oid) -> Result<WalkStream<T>>where
T: 'static,
pub fn walk(&self, oid: Oid) -> Result<WalkStream<T>>where
T: 'static,
Walk an OID subtree.
Auto-selects the optimal walk method based on SNMP version and WalkMode:
WalkMode::Auto(default): Uses GETNEXT for V1, GETBULK for V2c/V3WalkMode::GetNext: Always uses GETNEXTWalkMode::GetBulk: Always uses GETBULK (fails on V1)
Returns an async stream that yields each variable binding in the subtree.
The walk terminates when an OID outside the subtree is encountered or
when EndOfMibView is returned.
Uses the client’s configured oid_ordering, max_walk_results, and
max_repetitions (for GETBULK) settings.
§Example
// Auto-selects GETBULK for V2c/V3, GETNEXT for V1
let results = client.walk(oid!(1, 3, 6, 1, 2, 1, 1))?.collect().await?;Sourcepub fn walk_getnext(&self, oid: Oid) -> Walk<T>where
T: 'static,
pub fn walk_getnext(&self, oid: Oid) -> Walk<T>where
T: 'static,
Walk an OID subtree using GETNEXT.
This method always uses GETNEXT regardless of the client’s WalkMode configuration.
For auto-selection based on version and mode, use walk() instead.
Returns an async stream that yields each variable binding in the subtree.
The walk terminates when an OID outside the subtree is encountered or
when EndOfMibView is returned.
Uses the client’s configured oid_ordering and max_walk_results settings.
§Example
// Force GETNEXT even for V2c/V3 clients
let results = client.walk_getnext(oid!(1, 3, 6, 1, 2, 1, 1)).collect().await?;Sourcepub fn bulk_walk(&self, oid: Oid, max_repetitions: i32) -> BulkWalk<T>where
T: 'static,
pub fn bulk_walk(&self, oid: Oid, max_repetitions: i32) -> BulkWalk<T>where
T: 'static,
Walk an OID subtree using GETBULK (more efficient than GETNEXT).
Returns an async stream that yields each variable binding in the subtree. Uses GETBULK internally for better performance when walking large tables.
Uses the client’s configured oid_ordering and max_walk_results settings.
If max_repetitions is not specified, uses the client’s configured max_repetitions.
§Arguments
oid- The base OID of the subtree to walkmax_repetitions- How many OIDs to fetch per request
§Example
// Walk the interfaces table efficiently
let walk = client.bulk_walk(oid!(1, 3, 6, 1, 2, 1, 2, 2), 25);
// Process with futures StreamExtSourcepub fn bulk_walk_default(&self, oid: Oid) -> BulkWalk<T>where
T: 'static,
pub fn bulk_walk_default(&self, oid: Oid) -> BulkWalk<T>where
T: 'static,
Walk an OID subtree using the client’s configured max_repetitions.
This is a convenience method that uses the client’s max_repetitions setting
(default: 25) instead of requiring it as a parameter.
§Example
// Walk using configured max_repetitions
let walk = client.bulk_walk_default(oid!(1, 3, 6, 1, 2, 1, 2, 2));
// Process with futures StreamExt