summaryrefslogtreecommitdiffstats
path: root/src/ogRest.py
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-06-16 13:58:44 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-06-26 12:37:09 +0200
commit93f1b35fcddc432dc65dcd2a3eecc35de3230dae (patch)
tree2a960105cc63887642c344587e9e2527d19c96e2 /src/ogRest.py
parent0ada33c695b8ad5add42d6f39cdfd90ee99b6cf1 (diff)
Add syslog logs for HTTP requests and responses
This is useful for debuging and getting information on the processes that are being executed in ogclient. syslog outputs are something similar to: Jun 26 10:36:40 ogAdministrator /ogclient: GET refresh HTTP/1.1 Jun 26 10:36:40 ogAdministrator /ogclient: HTTP/1.0 500 Internal Server Err
Diffstat (limited to 'src/ogRest.py')
-rw-r--r--src/ogRest.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/ogRest.py b/src/ogRest.py
index 0578a82..eb3a848 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -15,6 +15,7 @@ import queue
import sys
import os
import signal
+import syslog
from src.restRequest import *
@@ -53,6 +54,13 @@ class restResponse():
else:
return self.msg
+ if response in {ogResponses.OK, ogResponses.IN_PROGRESS}:
+ syslog.syslog(syslog.LOG_INFO,
+ self.msg[:ogRest.LOG_LENGTH])
+ else:
+ syslog.syslog(syslog.LOG_ERR,
+ self.msg[:ogRest.LOG_LENGTH])
+
self.msg += '\r\n'
if json_body:
@@ -228,6 +236,8 @@ class ogResponses(Enum):
SERVICE_UNAVAILABLE=5
class ogRest():
+ LOG_LENGTH = 32
+
def __init__(self, config):
self.proc = None
self.terminated = False
@@ -252,11 +262,16 @@ class ogRest():
method = request.get_method()
URI = request.get_uri()
+ syslog.syslog(syslog.LOG_DEBUG, f'{method}{URI[:ogRest.LOG_LENGTH]}')
+
if (not "stop" in URI and
not "reboot" in URI and
not "poweroff" in URI and
not "probe" in URI):
if self.state == ThreadState.BUSY:
+ syslog.syslog(syslog.LOG_ERR,
+ 'Request has been received '
+ 'while ogClient is busy')
response = restResponse(ogResponses.SERVICE_UNAVAILABLE)
client.send(response.get())
return
@@ -271,6 +286,9 @@ class ogRest():
elif "refresh" in URI:
self.process_refresh(client)
else:
+ syslog.syslog(syslog.LOG_ERR,
+ f'Unsupported request: '
+ f'{method[:ogRest.LOG_LENGTH]}')
response = restResponse(ogResponses.BAD_REQUEST)
client.send(response.get())
elif ("POST" in method):
@@ -295,6 +313,9 @@ class ogRest():
elif ("image/create" in URI):
self.process_imagecreate(client, request)
else:
+ syslog.syslog(syslog.LOG_ERR,
+ f'Unsupported request: '
+ f'{method[:ogRest.LOG_LENGTH]}')
response = restResponse(ogResponses.BAD_REQUEST)
client.send(response.get())
else: