@NickF Do you have a github repo for this script?
Had the below issue with the 2.0 Beta script:
If i run python -m chardet.cli.chardetect /var/log/messages it response
msg: ISO-8859-1 with confidence 0.73
I believe I am running a standard install of truenas scale. (i.e. I don't believe I've adjusted file formats for log messages) The file may suppose to be UTF-8.
On a second Truenas core machine it reports back as 'ascii' , so TBH not sure what the default format of this file is. Anyhow forcing to ignore errors gets it going with the script ofr me.
The below change will resolve reading the log for 'invalid' content in the file encoding:
Code:
367: with open('/var/log/messages', 'r', encoding='UTF-8', errors='ignore') as file:
Or even removing encoding='UTF-8' and just set errors='ignore' Given I am not 100% confident the file is suppose to always be utf-8 encoded.
Error produced from script:
Code:
2023-09-11 08:09:37.764044 - Operating System version determined: TrueNAS SCALE, Version: 22.12.3.3 - Debian GNU/Linux 11 (bullseye) (TrueNAS SCALE)
Traceback (most recent call last):
File "/mnt/vol1/appdata/scripts/spencer.py", line 496, in <module>
matches, match_counts, repeat_errors = search_log_file(os_version)
File "/mnt/vol1/appdata/scripts/spencer.py", line 368, in search_log_file
for i, line in enumerate(file):
File "/usr/lib/python3.9/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 3062: invalid continuation byte