Brainstorm: Add cli tool as addon through docker

Hi everyone,
I need to have a cli tool that is not implemented in HA Core (in my case: ipmitools). My idea is to provide a addon (aka docker image) that uses just the base image and apt installing the cli tool.
So my dockerfile would look something like this:

ARG BUILD_FROM
FROM $BUILD_FROM

ENV LANG C.UTF-8

# Install requirements for add-on
RUN apk add --no-cache ipmitools

Now I have 2 questions left hoping you can point me in some right direction:

  1. Is this even feasable?
  2. How do I call/execute my addon from within HA just like a script?

As you can mabye see, I’m a HA development/docker-beginner. Any Help is appreciated.

Cheers!
Manu

If I am understanding your question correctly. I’m wondering if it would be a good idea to be spinning off processes with unknown ‘weight’ and effect within the HA sandbox? I think that is why the HA developers are pretty strict about what you can run. You can run scripts within HA sandbox, I have a couple light ones that query linux for cpu temp, fan speed and network specs. I run HA in a docker container on Ubuntu 20. However for heavy stuff like network bandwidth speed test I run in host space as cron job in this case, or run in parallel docker container. Most communicate back to HA via MQTT. You could use App Daemon, which again runs outside HA space, but has good direct interface to HA to create and query entities.

Here is a shell script sensor example:

# in sensors.yaml

# network bandwidth
  - platform: command_line
    name: Network Bandwidth
#    command: "shell_scripts/network-bandwidth.sh enp12s0f0" # builtin ethernet on macmini2012, flaky
    command: "shell_scripts/network-bandwidth.sh enxd0374516f37c" # usb ethernet on macmini2012
#    command: "shell_scripts/network-bandwidth.sh eth0"
#    commmand: "shell_scripts/network-bandwidth.sh wlan0"
    unit_of_measurement: "kB/s"
    value_template: "{{ value_json }}"
#    json_attributes_topic: '["timestamp","interface","in","out","units"]'
    json_attributes: 
      - "timestamp"
      - "interface"
      - "in"
      - "out"
      - "units"


# bash script
# be careful of my poor bash and linux abilities here


#!/bin/bash
# network-bandwidth.sh
# 202010161015

INTERVAL="1"  # update interval in seconds

if [ -z "$1" ]; then
        echo
        echo usage: $0 [network-interface]
        echo
        echo e.g. $0 eth0
        echo
        exit
fi

IF=$1

R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep $INTERVAL
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
TBPS=`expr $T2 - $T1`
RBPS=`expr $R2 - $R1`
TKBPS=`expr $TBPS / 1024`
RKBPS=`expr $RBPS / 1024`

#echo $TBPS
#echo $RBPS
#echo $TKBPS
#echo $RKBPS


#echo -e "{\"Hello\"}\n"
#echo "{\"timestamp\": $(date '+%Y%m%d%H%M%S'), \"interface\": \"$1\", \"speed\": {\"out\": $TKBPS, \"in\": $RKBPS}, \"units\": \"kB/s\"}"
echo "{\"timestamp\": $(date '+%Y%m%d%H%M%S'), \"interface\": \"${1}\", \"out\": \"${TKBPS}\", \"in\": \"${RKBPS}\", \"units\": \"kB/s\"}"



Can’t you put the executable somewhere within the Docker volume that gets mapped to HA? Or even add an additional volume that looks something like this:

'/usr/bin/ipmitool:/usr/local/bin/ipmitool:ro'

(which assumes you have installed ipmitools on the host)

Yes I believe you can. I just don’t know how heavy or what ipmtool needs access to. The whole user id thing within docker is a bit a pain at times, and the issues around having to sudo or equivalent for some things.

I can’t put the ipmitools on the host itself, since it is a standard installation on a Raspberry Pi 3. So I do not have a containerized installation.
The idea was also to provide an addon so others can use it as well.
And using a bash script isn’t possible if ipmitools is not present on the host (HA core).
I don’t think that ipmitools adds a lot of weight, since it is very similar to a ssh/wol command.
You just ipmitool -I lanplus -H 192.168.1.XX -U admin -P securepassword power on once and that’s all the magic.

Perhaps there’s a Python implementation for the protocol?