A Network UPS Tools (NUT) client library for Rust.
upsd
/nut-server
using TCPDo not use this library with critical UPS devices. This library is in early development and I cannot guarantee that it won't mess up your UPS configurations, and potentially cause catastrophic failure to your hardware.
Be careful and stay safe!
Check out the examples
directory for more advanced examples.
```rust use std::env; use std::net::ToSocketAddrs;
use nutclient::blocking::Connection; use nutclient::{Auth, ConfigBuilder, Host};
fn main() -> nutclient::Result<()> { let addr = env::var("NUTADDR") .unwraporelse(|| "localhost:3493".into()) .tosocket_addrs() .unwrap() .next() .unwrap();
let username = env::var("NUT_USER").ok();
let password = env::var("NUT_PASSWORD").ok();
let auth = username.map(|username| Auth::new(username, password));
let config = ConfigBuilder::new()
.with_host(Host::Tcp(addr))
.with_auth(auth)
.build();
let mut conn = Connection::new(config)?;
// Print a list of all UPS devices and their variables
println!("Connected UPS devices:");
for (name, description) in conn.list_ups()? {
println!("\t- Name: {}", name);
println!("\t Description: {}", description);
println!("\t Variables:");
for (var_name, var_val) in conn.list_vars(&name)? {
println!("\t\t- {} = {}", var_name, var_val);
}
}
Ok(())
} ```