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
Download history 79/week @ 2024-07-22 121/week @ 2024-07-29 106/week @ 2024-08-05 85/week @ 2024-08-12 140/week @ 2024-08-19 83/week @ 2024-08-26 135/week @ 2024-09-02 95/week @ 2024-09-09 88/week @ 2024-09-16 314/week @ 2024-09-23 244/week @ 2024-09-30 190/week @ 2024-10-07 198/week @ 2024-10-14 172/week @ 2024-10-21 122/week @ 2024-10-28 90/week @ 2024-11-04

587 downloads per month
Used in roboplc

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