Dependency-free basic SNMP v1/v2 client in Rust.
This is a fork of the original snmp crate which has been abandoned long time ago.
SNMP2 is a part of RoboPLC project.
New features added to the fork:
- SNMP v1 support
- MIBs support (requires
libnetsnmp) - Crate code has been refactored and cleaned up
- OIDs have been migrated to asn1
- Slightly improved PDU API, added a trap example
Supports:
- GET
- GETNEXT
- GETBULK
- SET
- Basic SNMP v1/v2 types
- Synchronous requests
- UDP transport
- MIBs (with
mibsfeature, requireslibnetsnmp)
Currently does not support:
- SNMPv3
TODO
- Transport-agnostic API
- SNMPv3
Examples
GET NEXT
use Duration;
use ;
let sys_descr_oid = from.unwrap;
let agent_addr = "198.51.100.123:161";
let community = b"f00b4r";
let timeout = from_secs;
let mut sess = new_v2c.unwrap;
let mut response = sess.getnext.unwrap;
if let Some = response.varbinds.next
GET BULK
use Duration;
use ;
let system_oid = from.unwrap;
let agent_addr = "[2001:db8:f00:b413::abc]:161";
let community = b"f00b4r";
let timeout = from_secs;
let non_repeaters = 0;
let max_repetitions = 7; // number of items in "system" OID
let mut sess = new_v2c.unwrap;
let response = sess.getbulk.unwrap;
for in response.varbinds
SET
use Duration;
use ;
let syscontact_oid = from.unwrap;
let contact = OctetString;
let agent_addr = "[2001:db8:f00:b413::abc]:161";
let community = b"f00b4r";
let timeout = from_secs;
let mut sess = new_v2c.unwrap;
let response = sess.set.unwrap;
assert_eq!;
for in response.varbinds
TRAPS
use UdpSocket;
use Pdu;
let socket = bind.expect;
loop
Working with MIBs
Prepare the system
apt-get install libsnmp-dev snmp-mibs-downloader
use ;
init
.unwrap;
let snmp_oid = from.unwrap;
let name = snmp_oid.mib_name.unwrap;
assert_eq!;
let snmp_oid2 = from_mib_name.unwrap;
assert_eq!;
Copyright
Copyright 2016 Hroi Sigurdsson
Copyright 2024 Serhij Symonenko, Bohemia Automation Limited
Licensed under the Apache License, Version 2.0 or the MIT license, at your option. This file may not be copied, modified, or distributed except according to those terms.