add: config-parser; fix: offline status internal server error
All checks were successful
/ update (push) Successful in 0s

This commit is contained in:
ahoemann 2024-12-12 08:11:13 +01:00
parent 80a0affc4b
commit 4d2fe89cd5
2 changed files with 25 additions and 11 deletions

5
adrianux.toml Normal file
View file

@ -0,0 +1,5 @@
[site]
git_url="http://localhost:5000"
website_url="http://localhost:8080"
[mode]
debug_mode=True

21
app.py
View file

@ -1,6 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from flask import Flask, render_template, redirect, url_for from flask import Flask, render_template, redirect, url_for
import requests import requests
import configparser
app = Flask(__name__) app = Flask(__name__)
@ -18,22 +20,29 @@ def homepage():
@app.route("/monitoring") @app.route("/monitoring")
def monitoring(): def monitoring():
git_status = get_status("https://git.adrianux.net") git_url = parser("site", "git_url")
website_status = get_status("https://adrianux.net") website_url = parser("site", "website_url")
return render_template("monitoring.html", git_status = git_status, website_status = website_status ) return render_template("monitoring.html", git_status = get_status(git_url), website_status = get_status(website_url) )
def get_status_code(link): def get_status_code(link):
requested_site = requests.get(link) requested_site = requests.get(link)
return requested_site.status_code return requested_site.status_code
def get_status(link): def get_status(link):
try:
match get_status_code(link): match get_status_code(link):
case 200: case 200:
return "ONLINE" return "ONLINE"
case 500:
return "ERROR"
case _: case _:
return "ERROR"
except:
return "OFFLINE" return "OFFLINE"
def parser(section, attribute):
config = configparser.RawConfigParser()
config.read("./adrianux.toml")
return config.get(section, attribute)
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug=False) mode = parser("mode","debug_mode")
app.run(debug=mode)