From e696b2a10b5639f0a63969d5570b4db5645729dc Mon Sep 17 00:00:00 2001 From: ahoemann Date: Fri, 29 Nov 2024 16:50:23 +0100 Subject: [PATCH 1/3] feat: site status --- app.py | 24 ++++++++++++++++++++++++ templates/monitoring.html | 9 +++++++++ 2 files changed, 33 insertions(+) create mode 100644 templates/monitoring.html diff --git a/app.py b/app.py index 9d2d472..9849e82 100755 --- a/app.py +++ b/app.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 from flask import Flask, render_template, redirect, url_for +import requests + app = Flask(__name__) navigation = {"Imprint":"imprint"} @app.route("/imprint") @@ -14,5 +16,27 @@ def about(): def homepage(): return render_template("homepage.html") +@app.route("/monitoring") +def monitoring(): + git_status = get("http://localhost:5000") + website_status = get("http://localhost:5000") + return render_template("monitoring.html", git_status = git_status, website_status = website_status ) + +def get_status_code(link): + requested_site = requests.get(link) + return requested_site.status_code + +def get(link): + match get_status_code(link): + case 200: + print(200) + return "ONLINE" + case 500: + print(500) + return "ERROR" + case _: + print("OTHER") + return "OFFLINE" + if __name__ == "__main__": app.run(debug=True) diff --git a/templates/monitoring.html b/templates/monitoring.html new file mode 100644 index 0000000..c41ec0b --- /dev/null +++ b/templates/monitoring.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block title %}Monitoring{% endblock %} +{% block head %} + {{ super() }} +{% endblock %} +{% block content %} +

Git status: {{ git_status }}

+

Website status: {{ website_status }}

+{% endblock %} -- 2.39.5 From 6860e318f5b3b3493f90a4dadfbc37a8d1c757eb Mon Sep 17 00:00:00 2001 From: ahoemann Date: Mon, 2 Dec 2024 11:07:12 +0000 Subject: [PATCH 2/3] replace: placeholder links --- app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 9849e82..4473c29 100755 --- a/app.py +++ b/app.py @@ -18,8 +18,8 @@ def homepage(): @app.route("/monitoring") def monitoring(): - git_status = get("http://localhost:5000") - website_status = get("http://localhost:5000") + git_status = get("https://git.adrianux.net") + website_status = get("https://adrianux.net") return render_template("monitoring.html", git_status = git_status, website_status = website_status ) def get_status_code(link): -- 2.39.5 From 00962295750b542100c3109c9ad9cc0f6abc09d9 Mon Sep 17 00:00:00 2001 From: ahoemann Date: Mon, 2 Dec 2024 11:28:15 +0000 Subject: [PATCH 3/3] fix: renamed function; fix: remove broken html --- app.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 4473c29..4d9604b 100755 --- a/app.py +++ b/app.py @@ -18,25 +18,25 @@ def homepage(): @app.route("/monitoring") def monitoring(): - git_status = get("https://git.adrianux.net") - website_status = get("https://adrianux.net") + git_status = get_status("https://git.adrianux.net") + website_status = get_status("https://adrianux.net") return render_template("monitoring.html", git_status = git_status, website_status = website_status ) def get_status_code(link): requested_site = requests.get(link) return requested_site.status_code -def get(link): +def get_status(link): match get_status_code(link): case 200: print(200) - return "ONLINE" + return "ONLINE" case 500: print(500) - return "ERROR" + return "ERROR" case _: print("OTHER") - return "OFFLINE" + return "OFFLINE" if __name__ == "__main__": app.run(debug=True) -- 2.39.5