56 lines
1.2 KiB
Python
Executable file
56 lines
1.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
from flask import Flask, render_template, redirect, url_for
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
import requests
|
|
import os
|
|
import time
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/imprint")
|
|
def root():
|
|
return render_template("imprint.html")
|
|
|
|
@app.route("/about")
|
|
def about():
|
|
return render_template("about.html")
|
|
|
|
@app.route("/")
|
|
def homepage():
|
|
return render_template("homepage.html")
|
|
|
|
@app.route("/monitoring")
|
|
def monitoring():
|
|
global git_status
|
|
global website_status
|
|
executor = ThreadPoolExecutor(2)
|
|
executor.submit(monitor)
|
|
return render_template("monitoring.html", git_status = git_status, website_status = website_status)
|
|
|
|
|
|
def get_status(link):
|
|
requested_site = requests.get(link)
|
|
status_code = requested_site.status_code
|
|
try:
|
|
match status_code:
|
|
case 200:
|
|
return "ONLINE"
|
|
case _:
|
|
return "ERROR"
|
|
except:
|
|
return "OFFLINE"
|
|
|
|
def monitor():
|
|
while True:
|
|
git_status = get_status(os.environ['GIT_URL'])
|
|
website_status = get_status(os.environ['WEBSITE_URL'])
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=os.environ['DEBUG_MODE'])
|
|
|
|
|
|
|