rups: A Network UPS Tools (NUT) implementation in Rust https://crates.io/crates/rups
Find a file
2021-07-31 03:28:32 -04:00
.cargo Save rupsc artifact 2021-07-31 02:05:24 -04:00
.github/workflows Save rupsc artifact 2021-07-31 02:05:24 -04:00
nut-client Add debug mode to rupsc. Fixes to parsing. 2021-07-31 03:28:32 -04:00
rupsc Add debug mode to rupsc. Fixes to parsing. 2021-07-31 03:28:32 -04:00
.gitignore Initial commit 2020-11-17 23:42:49 -05:00
Cargo.toml Initial commit for rupsc 2021-07-30 12:20:29 -04:00
LICENSE Initial commit 2020-11-17 23:42:49 -05:00
README.md version: 0.0.4 2020-11-18 02:14:53 -05:00

nut-client

crates.io Documentation MIT licensed CI

A Network UPS Tools (NUT) client library for Rust.

  • Connect to upsd/nut-server using TCP
  • Login with with username and password
  • List UPS devices
  • List variables for a UPS device

⚠️ Safety Goggles Required ⚠️

Do 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!

Example

Check out the examples directory for more advanced examples.

use std::env;
use std::net::ToSocketAddrs;

use nut_client::blocking::Connection;
use nut_client::{Auth, ConfigBuilder, Host};

fn main() -> nut_client::Result<()> {
    let addr = env::var("NUT_ADDR")
        .unwrap_or_else(|_| "localhost:3493".into())
        .to_socket_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
    println!("Connected UPS devices:");
    for (name, description) in conn.list_ups()? {
        println!("\t- Name: {}", name);
        println!("\t  Description: {}", description);

        // List UPS variables (key = val)
        println!("\t  Variables:");
        for var in conn.list_vars(&name)? {
            println!("\t\t- {}", var);
        }
    }

    Ok(())
}