Skript to read openhab logs

Hi there,

I created a small script which allows parsing of the openhab logfiles and then pushes the result back with the rest api.
This way I can automatically check my logs for errors and then send those through the pushover binding.
(I always forgot to check the logs regularly :innocent:)
Maybe this is useful for anybody else.
Check it out on github!

Log output:

2016-06-30 10:30:01.324 [INFO ] [org.openhab.model.script.Exec ] - 2 of 208 lines matched in /opt/openhab/logs/openhab.log
2016-06-30 12:30:01.432 [INFO ] [org.openhab.model.script.Exec ] - 0 of 11 lines matched in /opt/openhab/logs/openhab.log

Item Update:

2016-06-30 10:30:01 - LastError state updated to 2016-06-30 10:27:28.112 [ERROR] [.s.container.ContainerResponse] - The RuntimeException could not be mapped to a response, re-throwing to the HTTP container2016-06-30 10:27:28.127 [ERROR] [.a.h.ReflectorServletProcessor] - onRequest()
5 Likes

Thanks for your reply ( even if it’s the wrong thread. Maybe a mod can move it.).
This looks very good - I’ll try it immediately.
From looking at it the persistence-extension object seems to be missing?

I’m trying to implement your script but run in to problems with authentication:

python3 GetErrors.py -t
Invalid Dict-File at ‘files’!
Error: '[Errno 2] No such file or directory: ‘files’'
909 of 3031 lines matched in /opt/openhab/logs/openhab.log
Traceback (most recent call last):
File “GetErrors.py”, line 141, in
rest.put_status( element[“VAR”], sendstr)
File “/opt/openhab/etc/GetOpenhabErrors/oh_rest.py”, line 36, in put_status
req.raise_for_status()
File “/usr/lib/python3/dist-packages/requests/models.py”, line 825, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized

In openhab.log I see the following:

[WARN ] [.io.net.http.SecureHttpContext] - authInfos ‘l�’ must contain two elements separated by a colon

I did not test authentification, but it seems that I forgot to transfer user and password.
On github you find an updated version which should run fine.

Now I get the following warning

[WARN ] [.io.net.http.SecureHttpContext] - authInfos 'm���٥�ݕ��ͅ������͑��͝�����' must contain two elements separated by a colon

I tried to copy this from the rest-examples. Maybe there is an error. I’ll see if I can reproduce this this week. :slight_smile:

I did push a fix for the auth-issue to github. I tried it at home and it should work now.
Please let me know if this fixed the issue for you.

Now it’s working, thank you!

New Version available with minor performance Upgrades and tweaks

Added newlines for better readability when transferring through pushover

Update:
Fixed regex so errormessages over multiple lines are matched correctly.

1 Like

the module ? I guess refered to

Traceback (most recent call last):
File “/etc/openhab2/scripts/GetOpenhabErrors/GetErrors.py”, line 8, in
import oh_rest
ImportError: No module named oh_rest

I have solved this bit

Got it working, nice

Had to define item LastError, obviously
Had to set the paths of my logs being a ubuntu manual install non docker
Had to change files file permissions to rw

How can I test the rest api is causing LastError to update ?

Test calling GetErrors.py the seems to fill the logs with /n /n

Can I spot a specific ERROR or DEBUG then pass single entry back into openhab for use

Example ThingStatusInfoEvent changed from ONLINE to OFFLINE

You can modify the search expression in the config file and search for whatever you want :slight_smile:
Just create another entry with another search expression that pushes to the same item.