portal/storage: expose storage information via the portal

This commit is contained in:
Iain Learmonth 2022-11-01 10:17:31 +00:00
parent 1ee75fd37f
commit 293acba317
6 changed files with 121 additions and 7 deletions

View file

@ -1,9 +1,11 @@
import json
from datetime import datetime, timedelta, timezone
from typing import Optional
from flask import Blueprint, render_template, request, url_for, redirect
from flask.typing import ResponseReturnValue
from jinja2.utils import markupsafe
from markupsafe import Markup
from sqlalchemy import desc, or_, func
from app.alarms import alarms_for
@ -24,6 +26,7 @@ from app.portal.onion import bp as onion
from app.portal.pool import bp as pool
from app.portal.proxy import bp as proxy
from app.portal.smart_proxy import bp as smart_proxy
from app.portal.storage import bp as storage
from app.portal.webhook import bp as webhook
portal = Blueprint("portal", __name__, template_folder="templates", static_folder="static")
@ -38,6 +41,7 @@ portal.register_blueprint(onion, url_prefix="/onion")
portal.register_blueprint(pool, url_prefix="/pool")
portal.register_blueprint(proxy, url_prefix="/proxy")
portal.register_blueprint(smart_proxy, url_prefix="/smart")
portal.register_blueprint(storage, url_prefix="/state")
portal.register_blueprint(webhook, url_prefix="/webhook")
@ -91,6 +95,13 @@ def describe_brn(s: str) -> ResponseReturnValue:
return s
@portal.app_template_filter("pretty_json")
def pretty_json(input: Optional[str]):
if not input:
return "None"
return json.dumps(json.loads(input), indent=2)
def total_origins_blocked() -> int:
count = 0
for o in Origin.query.filter(Origin.destroyed.is_(None)).all():