ironsheep / RPi-Reporter-MQTT2HA-Daemon

Linux service to collect and transfer Raspberry Pi data via MQTT to Home Assistant (for RPi Monitoring)
GNU General Public License v3.0
460 stars 64 forks source link

Show Number Of Available Updates via APT #71

Closed codeclinic closed 1 year ago

codeclinic commented 1 year ago

Is your feature request related to a problem? Please describe. It would be great if this library could also show the number of available system updates on a system.

Describe the solution you'd like The MQTT message should include the number of available system (apt) updates, so that it can be displayed in Home Assistant.

Describe alternatives you've considered This info can be grabbed in python using the following code: import apt cache = apt.Cache() cache.open(None) cache.upgrade() return str(cache.get_changes().len())

Additional context The solution given above should work in this project. It would just need to be added to the posted MQTT message(s) for retrieval in Home Assistant

ironsheep commented 1 year ago

While non-ubuntu Debian distros don't have the update notifier as they don't distinguish between security updates and others there is a simple means to ask the packaging system what updates are available.

I'll put this in as a slow poll (maybe update the values every 4 hours?) and then push the count of packages needing an update. So this will be a single count, not two counts.

Sound ok?

codeclinic commented 1 year ago

Sure, I just need to be able to look at the info in Home Assistant and see which rPi devices need an apt upgrade

ironsheep commented 1 year ago

Well, this is problematic as getting this info so far required root access. I don't want to have us all give the Daemon account root access... so I need to find another way.

One thought I have is to provide a script that gets this data and deposits it as a tiny text file. The user can then set up this script to run under root cron say every 4 hours or so. The daemon reporter can simply forward this small text to the card.

Also, the user would run this script as part of the update run as well:

sudo apt-get update
sudo apt-get dist-upgrade
sudo {this tiny script}  # which then creates the tiny file saying no more updates are pending

oh.. and the tiny script appears to be:

sudo apt-get update
sudo apt-get --assume-no dist-upgrade >>{tiny-file}.txt 2>&1

(well there's probably more filtering on the output to reduce to only that which is useful but you get what I'm doing)

Thoughts?

codeclinic commented 1 year ago

Personally I'd prefer the setup to be as simple as possible without installing extra bits. The code snippet I provided would cover my needs.

However, I appreicate that you want this to be functional for as many systems as possible. So, perhaps I'm not the best person to comment.

Since, you already grab the OS info would it be an option to automatically deploy the python example I gave but prompt users of other OS's to add the extra script if their OS / system is detected as being none RPi ?

bsimmo commented 1 year ago

If this does go ahead, make it an opt in setting. I really don't wish my Pi's to be connecting to apt repositories to see if there are any updates, not only does it take resources from whatever it is doing but also takes time to update each repository. It may well be a low power device etc.

If I was to do this, I'd spin it out as a separate project and have its own program reporting to HA under its own entity. I don't know if the RPi update/updates section in HA can be used for that.?

Even then every month or at most a week or so would be best. Just my input.

On Sun, 19 Feb 2023, 5:36 pm Phill Healey, @.***> wrote:

Personally I'd prefer the setup to be as simple as possible without installing extra bits. The code snippet I provided would cover my needs.

However, I appreicate that you want this to be functional for as many systems as possible. So, perhaps I'm not the best person to comment.

Since, you already grab the OS info would it be an option to automatically deploy the python example I gave but prompt users of other OS's to add the extra script if their OS / system is detected as being none RPi ?

— Reply to this email directly, view it on GitHub https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/issues/71#issuecomment-1436047790, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN33B4ZHXXOCEO3JCMDWYJKYFANCNFSM6AAAAAAUJAUEPQ . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

codeclinic commented 1 year ago

I really don't wish my Pi's to be connecting to apt repositories to see if there are any updates, not only does it take resources from whatever it is doing but also takes time to update each repository. It may well be a low power device etc.

I was a contributer to a project very similar to this one that was abandoned about a year ago. In that project we used the python script given in my first post and there were no reported issues from any users regarding this particular function. I had it running on several different RPi devices including a couple of the original RPi Zeros.

The script literally only needs to be called once per week or even monthly. It's just to give you a heads-up that updates are available for the device. Any impact is negligable in my experience.

ironsheep commented 1 year ago

@codeclinic Jeez... I completely missed the fact the you have the small snippet of code at the head of this issue. I'm trying it out and and will push a set of releases (Daemon, card) when I get it all understood and implemented.

More soon.

bsimmo commented 1 year ago

I'm not against it, all for it in fact, just make it opt in. :-)

All the opt in is done in the setting file at the start with all the other parts you have to setup. It was also the every four hours mentioned, the few weeks/month as above I agree with. It needs to be it's own entity, not hidden in an attribute again. They're stupid things and make it harder to organise and trigger on in HA, not everyone uses the card.

On Sun, 19 Feb 2023, 10:21 pm Phill Healey, @.***> wrote:

I really don't wish my Pi's to be connecting to apt repositories to see if there are any updates, not only does it take resources from whatever it is doing but also takes time to update each repository. It may well be a low power device etc.

I was a contributer to a project very similar to this one that was abandoned about a year ago. In that project we used the python script given in my first post and there were no reported issues from any users regarding this particular function. I had it running on several different RPi devices including a couple of the original RPi Zeros.

The script literally only needs to be called once per week or even monthly. It's just to give you a heads-up that updates are available for the device. Any impact is negligable in my experience.

— Reply to this email directly, view it on GitHub https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/issues/71#issuecomment-1436113114, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN47SKJ3QDERRKZTEULWYKMFNANCNFSM6AAAAAAUJAUEPQ . You are receiving this because you commented.Message ID: @.***>

codeclinic commented 1 year ago

I completely missed the fact the you have the small snippet of code at the head of this issue.

No, problem. I thought you were saying you wanted a universally implementable option and so my suggestion wouldn't work. ;-)

ironsheep commented 1 year ago

ok, will appear in next release!

codeclinic commented 1 year ago

ok, will appear in next release!

Excellent!

ironsheep commented 1 year ago

Changes committed and now avail. in v1.8.0 and later.