From e7bdf0225ddf337fc7dba14855332686ed07c82c Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sat, 15 Jan 2022 08:09:12 +0100 Subject: [PATCH] implement simple overview --- server.py | 8 +++++++ templates/overview.html | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 templates/overview.html diff --git a/server.py b/server.py index e67cedd..ec12ad3 100755 --- a/server.py +++ b/server.py @@ -13,6 +13,7 @@ from sqlalchemy.exc import IntegrityError from sqlalchemy.sql import func import sqlalchemy from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql.expression import func app = flask.Flask("Icinga Report In Gateway") app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite' @@ -44,6 +45,13 @@ def buildReponseDict(status, service=None): "timestamp" : status.timestamp, "info" : status.info_text } +@app.route('/overview') +def overview(): + baseQuery = db.session.query(Status, func.max(Status.timestamp)) + query = baseQuery.group_by(Status.service).order_by(Status.service) + results = query.all() + return flask.render_template("overview.html", services=results, datetime=datetime.datetime) + @app.route('/alive') def alive(): # simple location for icinga alive checks via HTTP # diff --git a/templates/overview.html b/templates/overview.html new file mode 100644 index 0000000..6be440c --- /dev/null +++ b/templates/overview.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ {% for service in services %} +
+

{{ service[0].service }}

+ {{ datetime.fromtimestamp(service[0].timestamp).strftime("%H:%M %d.%m.%y") }} +
+ {% endfor %} +
+
+ +