2026-09-24 13:16:47 +05:00
2026-09-24 13:16:47 +05:00
2026-09-24 13:16:47 +05:00
2026-09-24 13:16:47 +05:00

jsonnutserver

Small HTTP server that runs upsc <ups> and returns the result as JSON.

GET /jsonstatus?=nutdev1@localhost

Requirements

  • Python 3 (standard library only)
  • upsc from the NUT client package, and a reachable upsd
# Debian/Ubuntu
sudo apt install python3 nut-client
# Fedora/RHEL
sudo dnf install python3 nut-client

Check that upsc works before going further:

upsc nutdev1@localhost

Install to /opt

sudo mkdir -p /opt/jsonnutserver
sudo install -m 0755 server.py /opt/jsonnutserver/server.py

systemd service

sudo install -m 0644 jsonnutserver.service /etc/systemd/system/jsonnutserver.service
sudo systemctl daemon-reload
sudo systemctl enable --now jsonnutserver.service

The unit runs /usr/bin/python3 /opt/jsonnutserver/server.py as an unprivileged DynamicUser and restarts it if it crashes. If python3 or upsc lives somewhere else on your system, adjust ExecStart (check with command -v python3).

Change the listen address or port

The server reads LISTEN_HOST (default 0.0.0.0) and LISTEN_PORT (default 8000). Override them without editing the unit file:

sudo systemctl edit jsonnutserver.service
[Service]
Environment=LISTEN_HOST=127.0.0.1
Environment=LISTEN_PORT=9000
sudo systemctl restart jsonnutserver.service

Check it

systemctl status jsonnutserver.service
journalctl -u jsonnutserver.service -f
curl 'http://localhost:8000/jsonstatus?=nutdev1@localhost'

Update

sudo install -m 0755 server.py /opt/jsonnutserver/server.py
sudo systemctl restart jsonnutserver.service

Uninstall

sudo systemctl disable --now jsonnutserver.service
sudo rm /etc/systemd/system/jsonnutserver.service
sudo systemctl daemon-reload
sudo rm -r /opt/jsonnutserver
S
Description
get nutserver in json
Readme
32 KiB
Languages
Python 100%