HomeAssistant monitoring plugin

Python appears to be part of at least the SSH addon container if not the base OS. I was able to pip3 install docker but then everything in home assistant got wobbly and I had to reboot. Next I tried a virtual environment and modified the check_mk_agent to activate it. At that point, the checks stopped completing. I gave up on that whole approach since even if the container is running, it doesn’t tell me if my automation failed or if my Sonos is offline (happened last month due to a bug in that integration).

I’ve got working code talking to the HA API. It doesn’t lend itself to easy monitoring. In my case, I’m using Cisco Mobility Express as a device tracker, so every single client shows up as an entity. If I add a new device, discovery will warn on it until I either create a discovery rule or mark it unmonitored. The state information for each device is specific to that device class. Some are numeric measurements, some are text. It will be a trial and error exercise to determine proper state for each device class unless perhaps I can find a decoder ring somewhere in the entity data. I’m only a couple hours into this so there may be a breakthrough waiting.

There is also the observer on http port 4357. It provides 3 very basic status messages for HA subsystems. Since looking at that should be a prerequisite before checking entities, I will likely just start there with beautifulsoup or another web scraper.

It’s a very simple start. I’m still working on parsing entities and states for better long-term visibility.

1 Like

Just to expand upon this, if you are running HAOS, you can get more accurate stats by running the below in the Individual program call instead of agent access after enabling SSH access to the host as mentioned here:

(Assuming check_mk_agent has been copied over to /config/check_mk_agent)

ssh -p 22222 root@$HOSTADDRESS$ docker exec homeassistant /config/check_mk_agent

Before this, using the SSH add-on, my Memory utilisation was like 10MB which didn’t seem right… Now it shows:

Similar for TCP Connections which always showed 1

Quite interesting indeed. I just never noticed it, but you’re right. It did report the memory in a strange way. But I wonder if it’s reported right this way as well. I run my HA on Proxmox and this is what I get for memory usage:
image

As you can see, there’s quite a difference between what is claimed from within the HA docker containder and what Proxmox actually tells me. Quite confusing this.

I think the discrepancy is due to it still running within a container, this time from within the homeassistant container and not the SSH addon.

I’ve did some further testing and able to now pull stats from HAOS itself allowing more accurate resource monitoring.

I copied the check_mk_agent to /mnt/data/ within HAOS however when running, it produced errors relating to illegal ‘-f’ option for some export commands. I removed the -f flag from the following lines within the check_mk_agent (lines 381-383) which allows it to run successfully:

    export -f run_mrpe
    export -f waitmax
    export -f run_cached

After updating the Individual program call instead of agent access command line as below, I was able to get more accurate stats:

ssh -p 22222 root@$HOSTADDRESS$ /mnt/data/check_mk_agent

This also updated the hostlabels within Check_MK to vm from containerized

It could be that once you do this, the two Memory values will match.

It probably is. I already had the monitoring on HAOS as well. Indeed that does show the correct values. Should have mentioned that I guess.

Hi folks! I’ve following up on these steps and got to actually trying to run check_mk_agent in the HAOS. It unfortunaly fails:

# /mnt/data/check_mk_agent
/mnt/data/check_mk_agent: line 340: syntax error: bad for loop variable

the code is for converting hex:

hex_decode() {
    # We might not have xxd available, so we have to do it manually.
    # Be aware that this implementation is very slow and should not be used for large data.
    local hex="$1"
    for ((i = 0; i < ${#hex}; i += 2)); do
        printf '%b' "\x${hex:i:2}"
    done
}

I’ve experimented a bit and it seems HAOS shell doesn’t like the (( operator. In fact, when I converted this function into sh-compatible the the check_mk_agent run a bit further (and failed on some other piece of code).

I think HAOS version of bash is an undercover busybox. None of bash --version or similar return the bash version. However, the binary is linked to busybox libs:

# strings /usr/bin/bash
/lib64/ld-linux-x86-64.so.2
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
lbb_prepare
ash_main
__cxa_finalize
__libc_start_main
libtirpc.so.3
libbusybox.so.1.36.1
libc.so.6
GLIBC_2.34
GLIBC_2.2.5
...

Is there check_mk_agent that I can try to run that would be compatible? Did anyone encountered this problem yet? I’m not sure how to proceed.

P.S. I’m on the newest checkmk and HAOS.

I’m happy to report that check_mk_agent.openwrt works instead of the linux version.

1 Like

I’m trying the HAOS-CheckMK-Plugin. I’ve got this error: (This is via cli, but the same within CheckMK)

OMD[mysite]:~$ check_haobserver.py homeassistant
<<<check_mk>>>
Version: 1.0
AgentOS: HomeAssistant
<<<local>>>
Traceback (most recent call last):
  File "/omd/sites/mysite/local/bin/check_haobserver.py", line 43, in <module>
    service=row.find('td', {'class': []}).contents[0].string.strip().replace(':','')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'contents'

Latest CheckMK on latest Proxmox Container Debian 12, latest HAOS in Proxmox VM. Thank you for helping.

If it is a busybox then the best approach is the agent for openwrt i would think.

Its fixed on github, issue #5. Thank you!