From 6f4619869313dadf1b807cd5ad5a08cbe78e1ec3 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Mon, 18 Dec 2023 20:33:58 +1100 Subject: [PATCH] Add ability to see history of http functions invocations --- app.py | 12 +++++ db.py | 8 ++++ templates/dashboard/http_functions.html | 12 +++-- templates/dashboard/http_functions/logs.html | 48 ++++++++++++++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 templates/dashboard/http_functions/logs.html diff --git a/app.py b/app.py index 5edf095..29a12db 100644 --- a/app.py +++ b/app.py @@ -139,6 +139,18 @@ def delete_http_function(): except Exception as e: return jsonify({"status": 'error', "message": str(e)}), 500 +@ app.route("/dashboard/http_functions/logs", methods=["GET"]) +def get_http_function_logs(): + name = request.args.get('name') + http_function = db.get_http_function(name) + if not http_function: + return jsonify({'error': 'Function not found'}), 404 + + http_function_id = http_function['id'] + http_function_invocations = db.get_http_function_invocations(http_function_id) + return render_template("dashboard/http_functions/logs.html", name=name, http_function_invocations=http_function_invocations) + + @ app.route("/dashboard/timer_functions", methods=["GET"]) def dashboard_timer_functions(): return render_template("dashboard/timer_functions.html") diff --git a/db.py b/db.py index 8402466..defd0c4 100644 --- a/db.py +++ b/db.py @@ -76,3 +76,11 @@ class DataBase(): def add_http_function_invocation(self, http_function_id, status, request_data, response_data, logs): self.execute( 'INSERT INTO http_function_invocations (http_function_id, status, request_data, response_data, logs) VALUES (%s, %s, %s, %s, %s)', [http_function_id, status, json.dumps(request_data), json.dumps(response_data), json.dumps(logs)], commit=True) + + def get_http_function_invocations(self, http_function_id): + http_function_invocations = self.execute( + """SELECT id, http_function_id, STATUS, invocation_time, request_data, response_data, LOGS +FROM http_function_invocations +WHERE http_function_id=9 +ORDER BY invocation_time DESC""", [http_function_id]) + return http_function_invocations \ No newline at end of file diff --git a/templates/dashboard/http_functions.html b/templates/dashboard/http_functions.html index f5b0d56..21aec91 100644 --- a/templates/dashboard/http_functions.html +++ b/templates/dashboard/http_functions.html @@ -47,9 +47,9 @@ + {% endfor %} diff --git a/templates/dashboard/http_functions/logs.html b/templates/dashboard/http_functions/logs.html new file mode 100644 index 0000000..78b4b8a --- /dev/null +++ b/templates/dashboard/http_functions/logs.html @@ -0,0 +1,48 @@ +
+

Logs: {{ name }}

+ +
+ +
+ +
Timestamp
+
Request
+
Response
+
Logs
+ + + {% for invocation in http_function_invocations %} + +
+ {{ invocation.invocation_time.strftime('%Y-%m-%d %H:%M:%S') }} + +
+ + +
+ {{ invocation.request_data }} +
+ + +
+ {{ invocation.response_data }} +
+ + +
+ {% for log in invocation.logs %} +
{{ log }}
+ {% endfor %} +
+ {% endfor %} +
\ No newline at end of file