382825085f
Nové SQL migrace pro alert_rules a alert_events v migrations.py (line 165). Nová ruční DB vrstva v alerting.py (line 7). Nové stránky a akce v routes/alerting.py (line 288):Alert pravidla, detail, vytvoření, úprava, smazání povolit/zakázat pravidlo Alert eventy a detail eventu s payload_json odkazy z job_id na detail úlohy detail pravidla s posledními eventy admin-only editor .sh alert skriptů v /opt/appfactory/workspace/appfactory-tools/alerts audit eventy podle zadání Menu Provoz → Alerting v layout.py (line 23). Router je zaregistrovaný v main.py (line 8).
100 lines
3.2 KiB
Python
100 lines
3.2 KiB
Python
import html
|
|
|
|
from ..config import PORTAL_PREFIX
|
|
|
|
APP_NAME = "CSBot Services Portal"
|
|
|
|
|
|
def page(title: str, body: str, user=None) -> str:
|
|
nav = ""
|
|
user_panel = ""
|
|
|
|
if user:
|
|
username = html.escape(user.get("username", ""))
|
|
display_name = html.escape(user.get("display_name") or user.get("username", ""))
|
|
nav = """
|
|
<nav>
|
|
<a class="nav-link" href="/portal/operations">Přehled</a>
|
|
<a class="nav-link" href="/portal/apps">Služby</a>
|
|
<div class="nav-menu">
|
|
<button type="button" class="nav-menu-button">Provoz</button>
|
|
<div class="nav-menu-panel">
|
|
<a href="/portal/jobs">Úlohy</a>
|
|
<a href="/portal/scheduled-scripts">Plánované skripty</a>
|
|
<a href="/portal/alerting/rules">Alerting</a>
|
|
<a href="/portal/deployments">Nasazení</a>
|
|
<a href="/portal/incidents">Incidenty</a>
|
|
<a href="/portal/workers">Workery</a>
|
|
</div>
|
|
</div>
|
|
<div class="nav-menu">
|
|
<button type="button" class="nav-menu-button">Správa</button>
|
|
<div class="nav-menu-panel">
|
|
<a href="/portal/audit">Audit</a>
|
|
<a href="/portal/backups">Zálohy</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
"""
|
|
user_panel = f"""
|
|
<div class="user-menu">
|
|
<span>{display_name}</span>
|
|
<span class="muted">@{username}</span>
|
|
<form method="post" action="/portal/logout">
|
|
<button type="submit" class="btn-secondary">Odhlásit</button>
|
|
</form>
|
|
</div>
|
|
"""
|
|
|
|
return f"""
|
|
<html>
|
|
<head>
|
|
<title>{APP_NAME} - {html.escape(title)}</title>
|
|
<link rel="stylesheet" href="{PORTAL_PREFIX}/static/styles.css">
|
|
<script src="{PORTAL_PREFIX}/static/portal.js"></script>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<a class="brand" href="/portal/operations" aria-label="{APP_NAME}">
|
|
<img src="{PORTAL_PREFIX}/static/csbot-logo.svg" alt="CSBOT">
|
|
<span>{APP_NAME}</span>
|
|
</a>
|
|
{nav}
|
|
{user_panel}
|
|
</header>
|
|
<main>
|
|
{body}
|
|
</main>
|
|
</body>
|
|
</html>
|
|
"""
|
|
|
|
|
|
def render_result(title, back_url, sections, extra_link=None, extra_label=None, user=None):
|
|
rendered_sections = ""
|
|
|
|
for section_title, content in sections:
|
|
rendered_sections += f"""
|
|
<h2>{html.escape(section_title)}</h2>
|
|
<pre>{html.escape(content)}</pre>
|
|
"""
|
|
|
|
extra = ""
|
|
if extra_link and extra_label:
|
|
extra = f'<p><a class="btn" href="{extra_link}">{html.escape(extra_label)}</a></p>'
|
|
|
|
return page(
|
|
title,
|
|
f"""
|
|
<div class="card">
|
|
<h2>{html.escape(title)}</h2>
|
|
{extra}
|
|
<p><a href="{back_url}">← Zpět</a></p>
|
|
</div>
|
|
<div class="card">
|
|
{rendered_sections}
|
|
</div>
|
|
""",
|
|
user=user,
|
|
)
|