HA on Ubuntu - monitor available OS updates?

I have HA running as docker containers on a UNC PC on an Ubuntu OS. On Ubuntu/Debian, default installs, there’s a cron task that will run apt update in the backend. When you log in via ssh, you’re given a nice display of # of updates are available, i.e.:

12 updates can be installed immediately.
3 of these updates are security updates.

Is there anyway to monitor / view this via the HA frontend? I don’t see any options in systemmonitor component.

1 Like

You could write a command line sensor to do that.

I don’t have any Ubuntu box running, but that looks to come from motd, so it should be possible to pull it relatively simply.

I see. Yup, looks like that is a way. They’re coming from apt-check --human-readable. Without the flag, the output returns as 12;3.

sensor:
  - platform: command_line
    name: System Updates
    scan_interval: 86400
    command: "/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 1"
  - platform: command_line
    name: Security Updates
    scan_interval: 86400
    command: "/usr/lib/update-notifier/apt-check 2>&1 | cut -d ';' -f 2"
2 Likes

Doh! Spoke too soon …

It’s not as simple when HA is running as a Docker container. Ugh. Back to the drawing board. Need to find a way to access it’s output from inside a container…

For others: what I’ve done was create a cron task that will export the output into /usr/share/hassio/share/system_updates.out then I accessed that through HA’s already existing share mount: /share/system_updates.out

New configuration is:

sensor:
  - platform: command_line
    name: System Updates
    scan_interval: 86400
    command: "cat /share/system_updates.out | cut -d ';' -f 1"
  - platform: command_line
    name: Security Updates
    scan_interval: 86400
    command: "cat /share/system_updates.out | cut -d ';' -f 2"
5 Likes

Care to share the cron task aswell. I may implement this.

Sure:

pz@hermes:/etc/cron.daily$ cat hassio-system-updates 
#!/bin/sh

/usr/lib/update-notifier/apt-check 2>&1 | tee /usr/share/hassio/share/system_updates.out

Pretty simple method. apt-check echos out in STDERR, ish, requring the STDERR > STDOUT redirect in order to get it into the output. For some reason using > wouldn’t work, I had to use tee in order to properly catch the output for the .out file.

/usr/share/hassio/share is the -v mounted /share directory within HA.

5 Likes

got this implemented, thanks for sharing!

Is there an option for Raspbian based installations? As far as I know there is no apt-check on Raspbian.

If you are using docker, you can set up SSH to run the command. You will need to create a SSH key for the user running your container so it can access your host. It will be run as the user running your container so appropriate permissions need to be given based on what you want to do. Example:

  - platform: command_line
    name: System; Security Updates
    scan_interval: 86400
    command: ssh -i /config/ssh/id_rsa hassuser@localhost "/usr/lib/update-notifier/apt-check"

To test if things are working within the container, jump into it using
docker exec -it [HA container name] bash

1 Like