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
454 stars 64 forks source link

Test failing after install #8

Closed DarKOrange75 closed 4 years ago

DarKOrange75 commented 4 years ago

Hi, these are the errors I receive after a fresh install and executing "python3 /opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py"

Traceback (most recent call last): File "/opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py", line 484, in getFileSystemDrives() File "/opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py", line 396, in getFileSystemDrives total_size_in_gb = '{:.0f}'.format(next_power_of_2(lineParts[1])) File "/opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py", line 411, in next_power_of_2 size_as_nbr = int(size) - 1 ValueError: invalid literal for int() with base 10: 'de'

Raspberry Pi 4B rev1.2 4GB Buster latest release Python 3.7 Thanks for your help.

ironsheep commented 4 years ago

Well sorry about that. Allways something new...

THere's a script call genBugInfo. Next to the .py file. Please run it and if you're will please attach the genBugInfo*.txt file it generates. It run the same commands so i should be able to see why my parser failed.

Then i'll get the fix in and release a new version for us all.

DarKOrange75 commented 4 years ago

Hi, thank you for your fast answer, here is the file you requested. genBugInfo-200805-103018.txt

ironsheep commented 4 years ago

Thanks for sending the file.

Well, that was unexpected... I better review that script.

I thought I'd see the output of 'df -m' in there but I'm not.

Could you please run 'df -m' on your device and reply with that output. I'll make sure to update my script, too.

fperezm commented 4 years ago

HI, I have the same problem, forgive me for intruding on the thread, in my case the result of executing 'df -m' is: S.ficheros bloques de 1M Usados Disponibles Uso% Montado en /dev/root 29769 4531 23998 16% / devtmpfs 3834 0 3834 0% /dev tmpfs 3963 0 3963 0% /dev/shm tmpfs 3963 9 3955 1% /run tmpfs 5 1 5 1% /run/lock tmpfs 3963 0 3963 0% /sys/fs/cgroup /dev/mmcblk0p1 253 54 199 22% /boot tmpfs 793 0 793 0% /run/user/1000

DarKOrange75 commented 4 years ago

Here is the output of 'df -m'

Sys. de fichiers blocs de 1M Utilisé Disponible Uti% Monté sur /dev/root 119774 41519 73358 37% / devtmpfs 1570 0 1570 0% /dev tmpfs 1699 0 1699 0% /dev/shm tmpfs 1699 33 1667 2% /run tmpfs 5 1 5 1% /run/lock tmpfs 1699 0 1699 0% /sys/fs/cgroup /dev/mmcblk0p1 253 55 198 22% /boot tmpfs 340 0 340 0% /run/user/1000

DarKOrange75 commented 4 years ago

Maybe our issue and this one are the same and it is related to the system language:

https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/issues/9#issue-673607224

My system is in French (see post above) @fperezm system is in Spanish @prankousky system is in German

I have tried with a English system on a Pi3B+ and it worked

demonio2332 commented 4 years ago

spanish system, same problem

ironsheep commented 4 years ago

OK, looking at this problem now. You all raise good points. If it is, it doesn't have to be language-dependent - I can code it differently. I'm working on this now.

DarKOrange75 commented 4 years ago

OK, looking at this problem now. You all raise good points. If it is, it doesn't have to be language-dependent - I can code it differently. I'm working on this now.

Great, thank you for your reactivity.

ironsheep commented 4 years ago

Fixes are committed, and appear in v1.4.1 and later. Please update to the latest and let me know if it's working now.

DarKOrange75 commented 4 years ago

Fixes are committed, and appear in v1.4.1 and later. Please update to the latest and let me know if it's working now.

Thanks Stephen, it's now working flawlessly!

ironsheep commented 4 years ago

You are very welcome. Glad you like the new card and daemon!

DarKOrange75 commented 4 years ago

You are very welcome. Glad you like the new card and daemon!

Thanks to you! You did a great and useful job.

demonio2332 commented 4 years ago

works perfect, thanks

fperezm commented 4 years ago

Great!, It's works. Thank you very much.

DarKOrange75 commented 4 years ago

Fixes are committed, and appear in v1.4.1 and later. Please update to the latest and let me know if it's working now.

Hi,

Sorry to bother you again but the issue reappeared after I added a network drive:

df -h Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur /dev/root 29G 2,3G 26G 9% / devtmpfs 184M 0 184M 0% /dev tmpfs 216M 0 216M 0% /dev/shm tmpfs 216M 18M 199M 9% /run tmpfs 5,0M 4,0K 5,0M 1% /run/lock tmpfs 216M 0 216M 0% /sys/fs/cgroup /dev/mmcblk0p1 253M 55M 198M 22% /boot //mafreebox.freebox.fr/Disque dur 229G 214M 217G 1% /media/Freebox tmpfs 44M 0 44M 0% /run/user/1000 /dev/sda1 58G 207M 55G 1% /mnt/exHDD

python3 /opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py Traceback (most recent call last): File "/opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py", line 499, in getFileSystemDrives() File "/opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py", line 411, in getFileSystemDrives total_size_in_gb = '{:.0f}'.format(next_power_of_2(lineParts[1])) File "/opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py", line 426, in next_power_of_2 size_as_nbr = int(size) - 1 ValueError: invalid literal for int() with base 10: 'dur'

ironsheep commented 4 years ago

Hi again! Yep, I possibly see why... is that white-space in your mount point: '//mafreebox.freebox.fr/Disque dur'? (what is the 'dur' part?)

Also, please provide 'df -m' output as that is what I'm parsing in the script.

I have an idea... I can work backwards from the value% field instead of working my way forward. This way i don't have to care about the white-space (if that's what it is.)

ironsheep commented 4 years ago

I push a change for this and other reasons. Fixes appear in v1.4.3 and later.

Please let me know if this fixes this issue.

DarKOrange75 commented 4 years ago

Hi again! Yep, I possibly see why... is that white-space in your mount point: '//mafreebox.freebox.fr/Disque dur'? (what is the 'dur' part?)

Also, please provide 'df -m' output as that is what I'm parsing in the script.

I have an idea... I can work backwards from the value% field instead of working my way forward. This way i don't have to care about the white-space (if that's what it is.)

Thank you! "Disque dur" means Hard Drive in French (Disque=Drive Dur=Hard). That's the name of my internet provider's box hard drive and I can't change it.

I'll update with the new code and let you know.

DarKOrange75 commented 4 years ago

The script is broken:

[2020-08-12 11:45:07] * MQTT connection established [2020-08-12 11:45:07] [2020-08-12 11:45:08] Announcing RPi Monitoring device to MQTT broker for auto-discovery ... Traceback (most recent call last): File "ISP-RPi-mqtt-daemon.py", line 981, in afterMQTTConnect() # now instead of after? File "ISP-RPi-mqtt-daemon.py", line 971, in afterMQTTConnect handle_interrupt(0) File "ISP-RPi-mqtt-daemon.py", line 956, in handle_interrupt update_values() File "ISP-RPi-mqtt-daemon.py", line 944, in update_values getLastUpdateDate() File "ISP-RPi-mqtt-daemon.py", line 538, in getLastUpdateDate pkg_install_date = datetime.strptime(pkg_date_string, '%Y-%m-%d %H:%M:%S').replace(tzinfo=local_tz) File "/usr/lib/python3.7/_strptime.py", line 577, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "/usr/lib/python3.7/_strptime.py", line 359, in _strptime (data_string, format)) ValueError: time data 'Fichier binaire' does not match format '%Y-%m-%d %H:%M:%S'

DarKOrange75 commented 4 years ago

Plus I don't get any information about the disk space in the MQTT payload

{"name": "Rpi Used Allskyweb", "uniq_id": "RPi-b827ebMonbc89e6_disk_used", "unit_of_measurement": "%", "stat_t": "~/monitor", "val_tpl": "{{ value_json.info.fs_free_prcnt }}", "~": "LaFosseliere/AllSky/sensor/rpi-allskyweb", "pl_avail": "online", "pl_not_avail": "offline", "ic": "mdi:sd", "avty_t": "~/status", "dev": {"identifiers": ["RPi-b827ebMonbc89e6"]}}

DarKOrange75 commented 4 years ago

df -m

Sys. de fichiers blocs de 1M Utilisé Disponible Uti% Monté sur /dev/root 29113 2268 25631 9% / devtmpfs 184 0 184 0% /dev tmpfs 216 0 216 0% /dev/shm tmpfs 216 10 207 5% /run tmpfs 5 1 5 1% /run/lock tmpfs 216 0 216 0% /sys/fs/cgroup /dev/mmcblk0p1 253 55 198 22% /boot //mafreebox.freebox.fr/Disque dur 233610 388 221334 1% /media/Freebox tmpfs 44 0 44 0% /run/user/1000 /dev/sda1 59058 217 55842 1% /mnt/exHDD

DarKOrange75 commented 4 years ago

Problem solved, I had to add --binary-files=text to the grep command line 524.

Your modifications seem to work now, the network drive information is reported in MQTT

Thank you!

ironsheep commented 4 years ago

@DarKOrange75 would you mind explaining what you solved by adding --binary-files=text to the grep command. Should I put this in for all to use?

And another question: would it be useful to put something to the effect of "script vx.x.x avail." on the card itself so we know which RPi's could use a reporter script update? Major versions only? What are your thoughts?

DarKOrange75 commented 4 years ago

@DarKOrange75 would you mind explaining what you solved by adding --binary-files=text to the grep command. Should I put this in for all to use?

And another question: would it be useful to put something to the effect of "script vx.x.x avail." on the card itself so we know which RPi's could use a reporter script update? Major versions only? What are your thoughts?

I solved this bug:

[2020-08-12 11:45:07] * MQTT connection established [2020-08-12 11:45:07] [2020-08-12 11:45:08] Announcing RPi Monitoring device to MQTT broker for auto-discovery ... Traceback (most recent call last): File "ISP-RPi-mqtt-daemon.py", line 981, in afterMQTTConnect() # now instead of after? File "ISP-RPi-mqtt-daemon.py", line 971, in afterMQTTConnect handle_interrupt(0) File "ISP-RPi-mqtt-daemon.py", line 956, in handle_interrupt update_values() File "ISP-RPi-mqtt-daemon.py", line 944, in update_values getLastUpdateDate() File "ISP-RPi-mqtt-daemon.py", line 538, in getLastUpdateDate pkg_install_date = datetime.strptime(pkg_date_string, '%Y-%m-%d %H:%M:%S').replace(tzinfo=local_tz) File "/usr/lib/python3.7/_strptime.py", line 577, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "/usr/lib/python3.7/_strptime.py", line 359, in _strptime (data_string, format)) ValueError: time data 'Fichier binaire' does not match format '%Y-%m-%d %H:%M:%S'

Grep was thinking that the log file was a binary file and not reading it, if I had the problem other people may encounter it so it won't hurt to add it to your code.

DarKOrange75 commented 4 years ago

And another question: would it be useful to put something to the effect of "script vx.x.x avail." on the card itself so we know which RPi's could use a reporter script update? Major versions only? What are your thoughts?

I think it is a good idea maybe for major versions, it depends how often you plan to push updates to your script. It could be annoying to have a new script alert everyday and people may start ignoring it.

ironsheep commented 4 years ago

I really appreciate your keeping in touch with things you find.

Thanks for the explanation of why the grep arg need. Yes, I'll add it. I wonder why it thinks one of the log files is binary?

I'm glad the script is working for you now!

re my update info question: I'm making a couple more updates to the daemon script: RAM sizes/usage, bit more CPU detail - core count, etc. and forwarding of the latest script release version (checked at boot-time, once every 24hrs after that) Sometime in the future, I'll then update the RPi card to optionally display the script update needed info

Yes, I'm still learning...

ironsheep commented 4 years ago

Ok, here are two things:

(1) What do you get for file /var/log/dpkg.log /var/log/dpkg.log.1

I get: $ file /var/log/dpkg.log /var/log/dpkg.log.1 /var/log/dpkg.log: ASCII text /var/log/dpkg.log.1: ASCII text

I'm wondering if for some reason your log.1 is compressed in which case we're going to need more fix than just telling grep to search is as a text file. Won't we?

(2) and if you're willing: What would be the best way to inform people of this script being updated? HACS informs us about the card updates but we've nothing for supporting scripts? Would it be best for me to use Twitter, Discord, forum, or?

DarKOrange75 commented 4 years ago

I really appreciate your keeping in touch with things you find.

Thanks for the explanation of why the grep arg need. Yes, I'll add it. I wonder why it thinks one of the log files is binary?

I'm glad the script is working for you now!

re my update info question: I'm making a couple more updates to the daemon script: RAM sizes/usage, bit more CPU detail - core count, etc. and forwarding of the latest script release version (checked at boot-time, once every 24hrs after that) Sometime in the future, I'll then update the RPi card to optionally display the script update needed info

Yes, I'm still learning...

Thanks to you Stephen, you did a nice job, exactly what I was looking for to monitor my AllSky camera.

DarKOrange75 commented 4 years ago

file /var/log/dpkg.log /var/log/dpkg.log.1

Here is the result for file /var/log/dpkg.log /var/log/dpkg.log.1 /var/log/dpkg.log: data /var/log/dpkg.log.1: data

Which explains the bug, doesn't seem to be compressed

For the updates, why not keep it simple? An announcement on top of this project homepage with version number / date and change log ? There is an option on top of the page to watch the project and get different level of alerts (new release, conversations, ...)

ironsheep commented 4 years ago

OK, grep fixes committed to repo. Fixes appear in v1.4.4 and later.

Yep, ChangeLog sounds good for now...

Thanks!

DarKOrange75 commented 4 years ago

OK, grep fixes committed to repo. Fixes appear in v1.4.4 and later.

Yep, ChangeLog sounds good for now...

Thanks!

Alert received, thank you.