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
|
31
app.py
31
app.py
|
@ -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):
|
||||||
match get_status_code(link):
|
try:
|
||||||
case 200:
|
match get_status_code(link):
|
||||||
return "ONLINE"
|
case 200:
|
||||||
case 500:
|
return "ONLINE"
|
||||||
return "ERROR"
|
case _:
|
||||||
case _:
|
return "ERROR"
|
||||||
return "OFFLINE"
|
except:
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in a new issue