Skip to content

Improved NUT docker image using forked Docker tools from instantlinux and building from source instructions

License

Notifications You must be signed in to change notification settings

balves42/docker-tools

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Megatec based UPS on Home Assistant

The following tutorial depicts my adventure in making a Megatec protocol based UPS working on Home Assistant either by compiling NUT from source or using this forked docker image.

UPS Home Assistant

I bought a cheap UPS in Portugal from a lesser known brand called "Eurotech", it came with some installation cd with a program called UPSmart which only works when it is plugged to a computer running windows:

I was very happy when i found out about the Network UPS Tools and i could finally connect my UPS to my Raspberry Pi running Home Assistant. But things were not so simple.

The problem

After connecting the USB cable, running a simple lsusb should have given me the information that i needed about the Product Id and Vendor Id:

lsusb

but the manufacturer didn't bothered to write it's real IDs and we have a bogus "Fry's Electronics MEC0003". After searching some open issues regarding the topic, i noticed that i needed to grab a newer version of NUT (version 2.8) which was not available on package managers. In this readme i provide instructions in how to build NUT from source or use this forked docker image for your purposes. This fork allows to set extra fields like subdriver, protocol, product, langid_fix and norating.

Build NUT from source

I used a pristine version of the Raspberry Pi OS (Bullseye) to build NUT. Other systems may vary.

Installing the requirements

sudo apt-get update -y
sudo apt-get install -y \
    ccache time git \
    git python2.7 perl curl \
    make autoconf automake libltdl-dev libtool-bin libtool \
    valgrind \
    cppcheck \
    pkg-config \
    gcc g++ clang \
    libcppunit-dev \
    libssl-dev libnss3-dev \
    augeas-tools libaugeas-dev augeas-lenses \
    libusb-dev libusb-1.0-0-dev \
    libi2c-dev \
    libmodbus-dev \
    libsnmp-dev \
    libpowerman0-dev \
    libfreeipmi-dev libipmimonitoring-dev \
    libavahi-common-dev libavahi-core-dev libavahi-client-dev \
    libneon27-gnutls-dev \
    libgd-dev \
    asciidoc source-highlight python3-pygments dblatex

Compiling NUT and installing

I downloaded the most recent version of nut when this tutorial was written (2.8.0):

wget https://github.com/networkupstools/nut/releases/download/v2.8.0/nut-2.8.0.tar.gz
tar xzvf nut-2.8.0.tar.gz
cd nut-2.8.0

And used the following command to configure what i wanted:

./configure --with-all --with-user=pi --with-group=pi --sysconfdir=/etc/nut --bindir=/usr/bin --sbindir=/usr/sbin

You can find more information about the selected options here. The command above installs all drivers and files (which may not be needed), sets the user and group (you should use yours if it is not pi) and sets the system directories for the configurations and binaries

Compile and install:

make
sudo make install

Getting the correct configuration

Edit the necessary configuration files present on the sysconfdir

sudo nano /etc/nut/ups.conf

The content of the file will be something like this:

maxretry=3
pollinterval=1

[eurotech]
    driver = "nutdrv_qx"
    subdriver = "hunnox"
    protocol = q1
    port = "auto"
    vendorid = "0001"
    productid = "0000"
    product = "MEC0003"
    norating
    novendor
    langid_fix = "0x0409"
    override.battery.packs = 1
    default.battery.voltage.high = "13.8"
    default.battery.voltage.low = "12"
    pollfreq = 1

Your main challenge will be finding out which combination of configurations will work for you. Mine was a result of checking the open issues and the driver documentation for drivers like blazer_ser, blazer_usb, nut_atcl_usb or nutdrv_qx and checking their subdrivers, protocols and langid_fixes. Don't ask me directly what will work in your UPS, it will be your own adventure.

You can debug your configuration and check if you can read the results of your UPS simply by running:

/usr/bin/nutdrv_qx -a eurotech -DDDDDD

The command needs to call the driver that you are using with the name of the UPS that you configured on /etc/nut/ups.conf

You can also try to autoscan to help you fill this file and try your luck with the command

nut-scanner -U

but the configurations that i got didn't work. When you find the right configuration you are ready to set your NUT server.

Setting up the server

Edit the file:

sudo nano /etc/nut/upsmon.conf

and add:

RUN_AS_USER root
MONITOR eurotech@localhost 1 admin secret master

eurotech should be the name of your configured UPS, admin and secret should be your username and password

Edit the file:

sudo nano /etc/nut/upsd.conf

and add:

LISTEN 0.0.0.0 3493

Edit the file:

sudo nano /etc/nut/nut.conf

and add:

MODE=netserver

Edit the file:

sudo nano /etc/nut/upsd.users

and fill with your username and password:

[monuser]
	password = secret
	admin master

Create some missing needed folders:

sudo mkdir -p /var/state/ups
sudo chmod 0770 /var/state/ups
sudo chown root:pi /var/state/ups

And enable some services:

sudo systemctl enable nut-server.service
sudo systemctl enable nut-monitor.service
sudo systemctl enable nut-driver-enumerator.service
sudo systemctl enable nut.target

Reboot at the end and test it by running

upsc eurotech@localhost

Installing using docker

Simply run the command with your desired options:

docker run -d \
-p 3493:3493 \
-e DESCRIPTION='eurotech' \
-e DRIVER='nutdrv_qx' \
-e SUBDRIVER='hunnox' \
-e PROTOCOL='q1' \
-e PRODUCT='MEC0003' \
-e LANGID_FIX='0x0409' \
-e NORATING='true' \
-e NOVENDOR='true' \
-e OVERRIDE_BATTERY_PACKS='1' \
-e DEFAULT_BATTERY_VOLTAGE_HIGH='13.8' \
-e DEFAULT_BATTERY_VOLTAGE_LOW='12' \
-e VENDORID='0001' \
-e PRODUCTID='0000' \
-e POLLINTERVAL='1' \
-e POLLFREQ='1' \
-e API_USER='admin' \
-e API_PASSWORD='secret' \
--restart always \
--name nut-upsd \
 --privileged \
brunoalves/nut-upsd:latest

Adding to Home Assistant

Add a new integration and select NUT, add the ip of the server where you installed it, the port and the desired username and password. All the information will be available as entities.

Scan interval workaround

The default scan interval is set to 60 seconds. If you go to the integration options you can set it to a minimum of 10 seconds

One way of editing this value directly without the GUI is to edit the file <homeassistant-config-folder>/.storage/core.config_entries

BACKUP THIS FILE FIRST!

Look for the line with the scan_interval of NUT and set it to 1 (for example)

Practical Docker Tools

Kubernetes is hard--or is it? This repo is a collection of multi-platform images and container resource definitions for managing a software-dev organization using Kubernetes. These tools make it easy. Contents:

Directory Description
ansible build your own cluster (Kubernetes or Swarm)
images images which are published to Docker Hub
k8s container resources in kubernetes yaml format
lib/build build makefile and tools
services non-clustered docker-compose services
ssl PKI certificate tools (deprecated by k8s)
stacks container resources in docker-compose format

Find images at docker hub/instantlinux. Each image is scanned by trivy to ensure they contain no known CVE vulnerabilities before promotion to Docker Hub.

Find a lot more details about the Kubernetes bare-metal installer in k8s/README.

Kubernetes capabilities

The cluster-deployment tools here include helm charts and ansible playbooks to spin up bare-metal or VM master/worker nodes, and a Makefile to add several additional features.

  • Direct-attached SSD local storage pools
  • Dashboard
  • Non-default namespace with its own service account (full permissions within namespace, limited read-only in kube-system namespaces)
  • Keycloak for OpenID / OAuth2 user authentication / authorization
  • Helm3
  • Mozilla sops with encryption (to keep credentials in local git repo)
  • Encryption for internal etcd
  • MFA using Authelia and Google Authenticator
  • Calico or flannel networking
  • ingress-nginx
  • Local-volume sync
  • Pod security policies
  • Automatic certificate issuing/renewal with Letsencrypt
  • PostgreSQL-operator from CrunchyData

Resource definitions

Developer infrastructure

Service Version Notes
artifactory ** binary repo
gitlab ** CI server and git repo
admin-git sync git repo across swarm
jira ** ticket tracking
mariadb-galera automatic cluster setup
nexus ** binary repo with docker registry
python-builder CI testing for python
python-wsgi WSGI runtime for python flask apps
wordpress **

Networking and support

Service Version Notes
authelia ** single-signon multi-factor auth
cloud ** nextcloud, private sync like Apple iCloud
data-sync poor-man's SAN for persistent storage
duplicati backups
ez-ipupdate Dynamic DNS client
haproxy-keepalived load balancer
guacamole ** authenticated remote-desktop server
logspout ** central logging for Docker
mysqldump per-database alternative to xtrabackup
nagios Nagios Core v4 for monitoring
nagiosql NagiosQL for configuring Nagios Core v4
nut-upsd Network UPS Tools
openldap OpenLDAP authentication server
restic ** backups
rsyslogd logger in a 13MB image
samba file server
samba-dc Active-Directory compatible domain controller
secondshot rsnapshot-based backups
splunk ** the free version

Email

Service Version Notes
blacklist a local rbldnsd for spam control
dovecot imapd server
postfix compact general-purpose image in 11MB
postfix-python postfix with spam-control scripts
rainloop ** webmail imapd-client server
spamassassin spam control daemon

Entertainment

Service Version Notes
davite party-invites manager like eVite
mt-daapd iTunes server
mythtv-backend MythTV backend
weewx Weather station software (Davis VantagePro2 etc.)
wxcam-upload Upload webcam images to Weather Underground

Credits

Thank you to the following contributors!

Contents created 2017-23 under Apache 2.0 License by Rich Braun.

About

Improved NUT docker image using forked Docker tools from instantlinux and building from source instructions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 26.7%
  • Python 21.7%
  • Perl 17.3%
  • Jinja 12.8%
  • Dockerfile 12.8%
  • Makefile 4.5%
  • Other 4.2%