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 |
#49 in #synchronous
437 downloads per month
Used in roboplc
49KB
1K
SLoC
RUST-SNMP
Dependency-free basic SNMPv2 client in Rust.
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);
}