Skip to main content

rusnmp/
lib.rs

1//! # rusnmp
2//!
3//! A lightweight, async SNMP v1/v2c/v3 client library for Rust.
4//!
5//! ## Quick Start (v2c)
6//!
7//! ```no_run
8//! use rusnmp::{SnmpClient, oid};
9//!
10//! #[tokio::main]
11//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
12//!     let mut client = SnmpClient::new("192.168.1.1", "public").await?;
13//!
14//!     // GET sysDescr
15//!     let result = client.get_one(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)).await?;
16//!     println!("sysDescr: {:?}", result.value.as_str());
17//!
18//!     // Walk ifTable
19//!     let entries = client.walk(&oid!(1, 3, 6, 1, 2, 1, 2, 2)).await?;
20//!     for vb in entries {
21//!         println!("{}: {:?}", vb.oid, vb.value);
22//!     }
23//!
24//!     Ok(())
25//! }
26//! ```
27//!
28//! ## SNMPv3 with USM
29//!
30//! ```no_run
31//! use rusnmp::{SnmpV3Client, oid};
32//! use rusnmp::v3::{UsmCredentials, AuthProtocol, PrivProtocol};
33//!
34//! #[tokio::main]
35//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
36//!     let creds = UsmCredentials::auth_priv(
37//!         "admin", AuthProtocol::Sha1, "authpass123",
38//!         PrivProtocol::Aes128, "privpass123",
39//!     );
40//!     let mut client = SnmpV3Client::new("192.168.1.1", creds).await?;
41//!
42//!     let result = client.get_one(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)).await?;
43//!     println!("sysDescr: {:?}", result.value.as_str());
44//!     Ok(())
45//! }
46//! ```
47//!
48//! ## Trap Receiver
49//!
50//! ```no_run
51//! use rusnmp::TrapReceiver;
52//!
53//! #[tokio::main]
54//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
55//!     let receiver = TrapReceiver::bind("0.0.0.0:162").await?;
56//!     loop {
57//!         let trap = receiver.recv().await?;
58//!         println!("Trap from {}: {:?}", trap.source, trap.varbinds);
59//!     }
60//! }
61//! ```
62
63mod client;
64pub mod codec;
65mod error;
66mod trap;
67mod types;
68#[cfg(feature = "v3")]
69pub mod v3;
70#[cfg(feature = "v3")]
71mod v3_client;
72
73pub use client::SnmpClient;
74pub use error::{SnmpError, Result};
75pub use trap::{Trap, TrapReceiver};
76pub use types::*;
77#[cfg(feature = "v3")]
78pub use v3_client::SnmpV3Client;