5 releases

Uses old Rust 2015

0.2.2 Apr 5, 2017
0.2.1 Jan 22, 2017
0.2.0 Jan 22, 2017
0.1.1 Oct 5, 2016
0.1.0 Oct 4, 2016

#46 in #synchronous

Download history 236/week @ 2023-12-10 294/week @ 2023-12-17 102/week @ 2023-12-24 231/week @ 2023-12-31 302/week @ 2024-01-07 232/week @ 2024-01-14 340/week @ 2024-01-21 253/week @ 2024-01-28 288/week @ 2024-02-04 299/week @ 2024-02-11 361/week @ 2024-02-18 174/week @ 2024-02-25 309/week @ 2024-03-03 47/week @ 2024-03-10 110/week @ 2024-03-17 25/week @ 2024-03-24

496 downloads per month

MIT/Apache

49KB
1K SLoC

RUST-SNMP

Dependency-free basic SNMPv2 client in Rust.

Documentation Build Status


lib.rs:

RUST-SNMP

Dependency-free basic SNMPv2 client in Rust.

Suppports:

  • GET
  • GETNEXT
  • GETBULK
  • SET
  • Basic SNMPv2 types
  • Synchronous requests
  • UDP transport

Currently does not support:

  • SNMPv1
  • SNMPv3
  • MIBs
  • Async requests
  • Transports other than UDP

TODO

  • Async requests
  • Walking function
  • Additional ObjectIdentifier utility methods
  • Decouple PDU building/parsing from socket handling
  • SNMPv3 (would require an external dependency)

Examples

GET NEXT

use std::time::Duration;
use snmp::{SyncSession, Value};

let sys_descr_oid = &[1,3,6,1,2,1,1,1,];
let agent_addr    = "198.51.100.123:161";
let community     = b"f00b4r";
let timeout       = Duration::from_secs(2);

let mut sess = SyncSession::new(agent_addr, community, Some(timeout), 0).unwrap();
let mut response = sess.getnext(sys_descr_oid).unwrap();
if let Some((_oid, Value::OctetString(sys_descr))) = response.varbinds.next() {
    println!("myrouter sysDescr: {}", String::from_utf8_lossy(sys_descr));
}

GET BULK

use std::time::Duration;
use snmp::SyncSession;

let system_oid      = &[1,3,6,1,2,1,1,];
let agent_addr      = "[2001:db8:f00:b413::abc]:161";
let community       = b"f00b4r";
let timeout         = Duration::from_secs(2);
let non_repeaters   = 0;
let max_repetitions = 7; // number of items in "system" OID

let mut sess = SyncSession::new(agent_addr, community, Some(timeout), 0).unwrap();
let response = sess.getbulk(&[system_oid], non_repeaters, max_repetitions).unwrap();

for (name, val) in response.varbinds {
    println!("{} => {:?}", name, val);
}

SET

use std::time::Duration;
use snmp::{SyncSession, Value};

let syscontact_oid  = &[1,3,6,1,2,1,1,4,0];
let contact         = Value::OctetString(b"Thomas A. Anderson");
let agent_addr      = "[2001:db8:f00:b413::abc]:161";
let community       = b"f00b4r";
let timeout         = Duration::from_secs(2);

let mut sess = SyncSession::new(agent_addr, community, Some(timeout), 0).unwrap();
let response = sess.set(&[(syscontact_oid, contact)]).unwrap();

assert_eq!(response.error_status, snmp::snmp::ERRSTATUS_NOERROR);
for (name, val) in response.varbinds {
    println!("{} => {:?}", name, val);
}

No runtime deps