gjr80 / weewx-saratoga

A WeeWX extension to support the Saratoga Weather Website Templates
GNU Affero General Public License v3.0
3 stars 2 forks source link

`post-clientraw.php` does not log a malformed/miscreant `clientraw.txt` #8

Closed gjr80 closed 3 years ago

gjr80 commented 3 years ago

Today I accidental had rtcr generate a malformed clientraw.txt. Of course clientraw.txt was not being updated on my web server and I proceeded to fault find. I could see clientraw.txt appearing on my WeeWX machine but did not notice the malformation. there were no errors in the WeeWX log. I looked at my web server and confirmed no clientraw.txt was being saved anywhere. I checked the web server error log and no errors. I checked the web server access log and could clearly see post-clientaw.php sending/logging a 200 response. I eventually discovered the malformed clientraw.txt. The problem with clientraw.txt was that it did not pass the end of file record check so the content was discarded. It would have been useful if something was logged when the content was discarded.

In an earlier rtcr I had the web server send back a simple character string 'OK' to indicate to rtcr that the file was received OK. This stopped working under python3 and I have not been able to get python 3 to recognise the response. This would have helped by placing an entry in the WeeWX log.

Perhaps the post-clientraw.php script should log receipt of a malformed clientraw.txt.

ktrue commented 3 years ago

You're correct, the post_clientraw.php didn't provide any feedback. I've updated the script with HTTP error codes in eb9e7f3

Now, the script will return the following codes:

'200 - OK' for proper operation '400 - Bad Request' for malformed POST request (clientraw missing/malformed) '405 - Method Not Allowed' for GET or HEAD requests '507 - Insufficient Storage' if writing clientraw.txt to disk fails

Those HTTP response codes will be logged in the webserver's access_log for each request (previously, only '200' was logged irrespective of actual success).

Script installed and working on my site.

gjr80 commented 3 years ago

Great solution! I reworked the rtcr.py logging and managed to extract a little more info from the response received by rtcr.py. The log now distinguishes between a successful post (200) and a failure (any of the other codes). Under normal logging nothing will show in the WeeWX log regards the success of the HTTP POST or otherwise. If you set debug = 1 in weewx.conf and do a WeeWX config reload or restart you will see the response codes and message logged for each HTTP POST. You can also enable just debug logging of HTTP POSTs (rather than full WeeWX debug logging) by setting debug_post = True under [WeewxSaratoga] [[RealtimeClientraw]].

I will have to borrow some of the post_clientraw.php code and use in a similar php file I use to HTTP POST the realtime gauge-data.txt file used by WeeWX to feed the SteelSeries Weather Gauges.