This commit is contained in:
parent
2b6885055b
commit
709b0fbe21
1 changed files with 60 additions and 33 deletions
93
app.py
93
app.py
|
@ -1,42 +1,69 @@
|
||||||
#!/usr/bin/env python3
|
package main
|
||||||
from flask import Flask, render_template, redirect, url_for
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
@app.route("/imprint")
|
var templates = template.Must(template.ParseGlob("*.html"))
|
||||||
def root():
|
|
||||||
return render_template("imprint.html")
|
|
||||||
|
|
||||||
@app.route("/about")
|
func main() {
|
||||||
def about():
|
mode := os.Getenv("DEBUG_MODE")
|
||||||
return render_template("about.html")
|
if mode == "true" {
|
||||||
|
log.Println("Debug mode is on")
|
||||||
|
}
|
||||||
|
http.HandleFunc("/imprint", imprint)
|
||||||
|
http.HandleFunc("/about", about)
|
||||||
|
http.HandleFunc("/", homepage)
|
||||||
|
http.HandleFunc("/monitoring", monitoring)
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
||||||
|
|
||||||
@app.route("/")
|
func imprint(w http.ResponseWriter, r *http.Request) {
|
||||||
def homepage():
|
renderTemplate(w, "imprint.html")
|
||||||
return render_template("homepage.html")
|
}
|
||||||
|
|
||||||
@app.route("/monitoring")
|
func about(w http.ResponseWriter, r *http.Request) {
|
||||||
def monitoring():
|
renderTemplate(w, "about.html")
|
||||||
git_url = os.environ['GIT_URL']
|
}
|
||||||
website_url = os.environ['WEBSITE_URL']
|
|
||||||
return render_template("monitoring.html", git_status = get_status(git_url), website_status = get_status(website_url) )
|
|
||||||
|
|
||||||
def get_status_code(link):
|
func homepage(w http.ResponseWriter, r *http.Request) {
|
||||||
requested_site = requests.get(link)
|
renderTemplate(w, "homepage.html")
|
||||||
return requested_site.status_code
|
}
|
||||||
|
|
||||||
def get_status(link):
|
func monitoring(w http.ResponseWriter, r *http.Request) {
|
||||||
try:
|
gitURL := os.Getenv("GIT_URL")
|
||||||
match get_status_code(link):
|
websiteURL := os.Getenv("WEBSITE_URL")
|
||||||
case 200:
|
gitStatus := getStatus(gitURL)
|
||||||
return "ONLINE"
|
websiteStatus := getStatus(websiteURL)
|
||||||
case _:
|
data := struct {
|
||||||
return "ERROR"
|
GitStatus string
|
||||||
except:
|
WebsiteStatus string
|
||||||
|
}{
|
||||||
|
GitStatus: gitStatus,
|
||||||
|
WebsiteStatus: websiteStatus,
|
||||||
|
}
|
||||||
|
renderTemplate(w, "monitoring.html", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderTemplate(w http.ResponseWriter, tmpl string, data ...interface{}) {
|
||||||
|
err := templates.ExecuteTemplate(w, tmpl, data)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStatus(link string) string {
|
||||||
|
resp, err := http.Get(link)
|
||||||
|
if err != nil {
|
||||||
return "OFFLINE"
|
return "OFFLINE"
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return "ONLINE"
|
||||||
|
}
|
||||||
|
return "ERROR"
|
||||||
|
}
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
mode = os.environ['DEBUG_MODE']
|
|
||||||
app.run(debug=mode)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue