Network UPS Tools (NUT)

repository·master·Indexed 24 days ago

https://github.com/networkupstools/nut

A comprehensive, layered framework for monitoring and managing Uninterruptible Power Supplies (UPS), Power Distribution Units (PDU), and other power-related hardware over a network. Documentation covers installation from source or binary packages, CGI web interface integration, system user and permission configuration, and an extended Semantic Versioning (SEMVER) system for releases and development snapshots.

Tokens
22.4K
Snippets
40
Records
181
Agent score
87%

What's inside NUT

  1. Overview of Network UPS Tools (NUT) Architecture

    master

    Network UPS Tools (NUT) is a layered collection of programs designed to monitor and administer UPS (Uninterruptible Power Supply), PDU (Power Distribution Unit), and SCD hardware.

    Its architecture consists of three main layers:

    1. Drivers: Communicate directly with specific hardware models, translating device-specific protocols into a common compatibility layer.
    2. Server (upsd): Caches information from the drivers and serves it over the network to authorized clients.
    3. Clients: Monitor status and perform actions (like clean shutdowns) based on data received from upsd.

    This layered approach allows multiple systems to monitor a single large UPS and enables centralized management of power devices.

  2. Overview of the NUT command-line installer

    master

    The scripts/installer/ directory contains scripts and data for NUT packaging (formerly known as Eaton IPSS Unix, IPP for Unix, or UPP). It provides an interactive text-mode installer for target deployments, covering:

    • Package (re-)installation
    • Initial device discovery
    • Password setup
    • Shutdown handling via helper scripts
    • Status overview via helper scripts

    The installer relies on the nutconf tool, which is part of the NUT source tree.

  3. Overview of NUT libraries

    master

    NUT provides several libraries to facilitate interfacing with 3rd party programs and internal components:

    • libupsclient: Used to interact with the NUT server (upsd).
    • libnutclient: Provides a high-level interface to interact with the NUT server.
    • libnutscan: Used to discover NUT-supported devices.

    Note on Installation: Runtime libraries are installed by default. To install development files (headers, static/shared libraries, and compilation helpers), you must provide the --with-dev flag to the configure script during the build process.

  4. Manage NUT drivers with nut-driver-enumerator

    master

    NUT provides mechanisms to manage drivers as systemd service instances using the nut-driver-enumerator.sh script and the upsdrvsvcctl tool. There are two ways to deploy these services:

    1. Daemon Mode (nut-driver-enumerator-daemon* units): Runs the enumerator as a continuous daemon to regularly inspect and apply NUT configurations to OS service units. This is intended for monitoring systems with dynamic power devices or where filesystem event monitoring is unreliable.
    2. One-shot Mode (nut-driver-enumerator.* units): Runs the script once per trigger (typically during system boot or when configuration changes are detected by systemd).
  5. Understand the Primary/Secondary mode transition

    master

    NUT has deprecated the Master/Slave terminology in favor of Primary/Secondary modes for upsmon clients.

    • Configuration: Keywords in upsd.users and upsmon.conf for Master/Slave are supported for backwards compatibility, but they are no longer documented.
    • Protocol Behavior: upsmon now attempts to elevate privileges with a PRIMARY <ups> request first, falling back to MASTER <ups> for compatibility with older upsd servers.
    • Implementation: The protocol now returns OK PRIMARY-GRANTED for new clients and OK MASTER-GRANTED for legacy clients.
  6. Integrate NUT with external APIs using integration scripts

    master
    The scripts/external_apis directory contains scripts designed to integrate Network UPS Tools (NUT) with external devices or services that do not have native NUT drivers. These scripts can implement protocols such as REST APIs or Web-based JSON. They serve as both ready-to-use integrations for existing installations and as templates for developing new custom integrations.
  7. Understand NUT Semantic Versioning (SEMVER)

    master

    NUT uses an extended Semantic Versioning system to distinguish between official releases and development snapshots.

    Standard Semver (Releases):

    • X: MAJOR - Incompatible API changes.
    • Y: MINOR - Major new features or API evolution.
    • Z: PATCH - Bug fixes and new drivers.

    Extended Semver (Snapshots/Trunk): For development builds, NUT adds optional components to the triplet: X.Y.Z(.T(.B(-C+H(+R)))).

    • T: Commits on trunk since the previous release tag.
    • B: Commits on a feature branch since its nearest ancestor on the trunk.
    • C: Commits on a branch since the previous release tag.
    • H: (Short) Git hash of the commit (prefixed with 'g').
    • R: Pre-release information (e.g., rc6).

    Note: Unlike standard Semver where pre-release versions are 'less than' the release, NUT's 4th and 5th numeric components are considered 'greater than' the base release to allow development builds to be formally installed over preceding releases.

  8. Install and build the execfuse daemon

    master

    To use the NUT access via FUSE proof-of-concept, you must first install FUSE development libraries and build the execfuse daemon.

    Prerequisites:

    • Debian-like systems: apt install libfuse-dev
    • MacOS (via Homebrew): brew install --cask macfuse@dev

    Build steps:

    1. Clone the execfuse repository.
    2. Build using make to produce the execfuse binary.
    apt install libfuse-dev  # For Debian-like systems
    
    # Build execfuse
    git clone https://github.com/vi/execfuse
    cd execfuse
    make && ls -la execfuse
  9. Integrate non-native protocols via External APIs

    master

    NUT supports integrating non-native protocols as live-stream input for the dummy-ups driver. An example implementation is provided in scripts/external_apis. To enable this capability during build, use the following configure flag:

    configure --enable-extapi-enphase
  10. Configure upssched with a lock file

    master
    If you use upsssched, you must define the LOCKFN directive to prevent race conditions where multiple instances of upsssched attempt to start simultaneously. Failure to define this may cause the program to fail.