add: config-parser; fix: offline status internal server error
All checks were successful
/ update (push) Successful in 0s
All checks were successful
/ update (push) Successful in 0s
This commit is contained in:
parent
80a0affc4b
commit
4d2fe89cd5
2 changed files with 25 additions and 11 deletions
5
adrianux.toml
Normal file
5
adrianux.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
[site]
|
||||
git_url="http://localhost:5000"
|
||||
website_url="http://localhost:8080"
|
||||
[mode]
|
||||
debug_mode=True
|
21
app.py
21
app.py
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
from flask import Flask, render_template, redirect, url_for
|
||||
import requests
|
||||
import configparser
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
@ -18,22 +20,29 @@ def homepage():
|
|||
|
||||
@app.route("/monitoring")
|
||||
def monitoring():
|
||||
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 )
|
||||
git_url = parser("site", "git_url")
|
||||
website_url = parser("site", "website_url")
|
||||
return render_template("monitoring.html", git_status = get_status(git_url), website_status = get_status(website_url) )
|
||||
|
||||
def get_status_code(link):
|
||||
requested_site = requests.get(link)
|
||||
return requested_site.status_code
|
||||
|
||||
def get_status(link):
|
||||
try:
|
||||
match get_status_code(link):
|
||||
case 200:
|
||||
return "ONLINE"
|
||||
case 500:
|
||||
return "ERROR"
|
||||
case _:
|
||||
return "ERROR"
|
||||
except:
|
||||
return "OFFLINE"
|
||||
|
||||
def parser(section, attribute):
|
||||
config = configparser.RawConfigParser()
|
||||
config.read("./adrianux.toml")
|
||||
return config.get(section, attribute)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=False)
|
||||
mode = parser("mode","debug_mode")
|
||||
app.run(debug=mode)
|
||||
|
|
Loading…
Reference in a new issue