Skip to main content

Crate rusnmp

Crate rusnmp 

Source
Expand description

§rusnmp

A lightweight, async SNMP v1/v2c/v3 client library for Rust.

§Quick Start (v2c)

use rusnmp::{SnmpClient, oid};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = SnmpClient::new("192.168.1.1", "public").await?;

    // GET sysDescr
    let result = client.get_one(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)).await?;
    println!("sysDescr: {:?}", result.value.as_str());

    // Walk ifTable
    let entries = client.walk(&oid!(1, 3, 6, 1, 2, 1, 2, 2)).await?;
    for vb in entries {
        println!("{}: {:?}", vb.oid, vb.value);
    }

    Ok(())
}

§SNMPv3 with USM

use rusnmp::{SnmpV3Client, oid};
use rusnmp::v3::{UsmCredentials, AuthProtocol, PrivProtocol};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let creds = UsmCredentials::auth_priv(
        "admin", AuthProtocol::Sha1, "authpass123",
        PrivProtocol::Aes128, "privpass123",
    );
    let mut client = SnmpV3Client::new("192.168.1.1", creds).await?;

    let result = client.get_one(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)).await?;
    println!("sysDescr: {:?}", result.value.as_str());
    Ok(())
}

§Trap Receiver

use rusnmp::TrapReceiver;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let receiver = TrapReceiver::bind("0.0.0.0:162").await?;
    loop {
        let trap = receiver.recv().await?;
        println!("Trap from {}: {:?}", trap.source, trap.varbinds);
    }
}

Modules§

codec
BER (Basic Encoding Rules) codec for SNMP PDUs.
v3
SNMPv3 User-based Security Model (USM) implementation.

Macros§

oid
Macro to create an OID from literal components.

Structs§

Oid
An SNMP Object Identifier (OID).
SnmpClient
Async SNMP client for v1/v2c.
SnmpV3Client
Async SNMPv3 client with USM authentication and privacy.
Trap
A received SNMP trap/notification.
TrapReceiver
Async SNMP trap receiver.
VarBind
A variable binding (OID + value pair).

Enums§

SnmpError
Value
SNMP value types.
Version
SNMP protocol version.

Type Aliases§

Result