icons, main .env

This commit is contained in:
JiriUhlir
2026-06-15 14:07:16 +02:00
parent 35d857f653
commit fa4307852c
12 changed files with 773 additions and 220 deletions
+19 -7
View File
@@ -20,10 +20,11 @@ from app.db.alerting import (
from app.db.audit import log_audit_event
from app.routes.jobs import pretty_json
from app.templates.layout import page
from app.tools_repo import TOOLS_REPO_DIR, commit_and_push
router = APIRouter()
ALERTS_DIR = Path("/opt/appfactory/workspace/appfactory-tools/alerts")
ALERTS_DIR = TOOLS_REPO_DIR / "alerts"
MAX_SCRIPT_BYTES = 100 * 1024
EVENT_TYPES = ("incident.opened", "incident.resolved")
DEFAULT_SCRIPT_CONTENT = """#!/usr/bin/env bash
@@ -325,7 +326,7 @@ def alert_rules_page(request: Request, user=Depends(require_user)):
"Alert pravidla",
f"""
<div class="card">
<h2>Alert pravidla</h2>
<h2><i class="fa-solid fa-bell" aria-hidden="true"></i> Alert pravidla</h2>
<p class="muted">Správa pravidel pro spouštění alert skriptů při událostech incidentů.</p>
<p>
<a class="btn" href="/portal/alerting/rules/new">+ Nové alert pravidlo</a>
@@ -360,7 +361,7 @@ def new_alert_rule_form(request: Request, user=Depends(require_user)):
"Nové alert pravidlo",
f"""
<div class="card">
<h2>Nové alert pravidlo</h2>
<h2><i class="fa-solid fa-circle-plus" aria-hidden="true"></i> Nové alert pravidlo</h2>
<p><a class="btn" href="/portal/alerting/rules">&larr; Zpět</a></p>
</div>
<div class="card">
@@ -383,6 +384,10 @@ def create_alert_rule_action(
):
metadata = form_metadata(name, description, event_type, service_id, script_name, is_enabled)
rule_id = create_alert_rule(metadata)
created_name = metadata["script_name"]
if not script_path(created_name).exists():
save_script_file(created_name, DEFAULT_SCRIPT_CONTENT)
commit_and_push(f"alerts/{created_name}", f"Vytvořen alert skript {created_name}", user)
log_audit_event(
user,
action="alert_rule.created",
@@ -407,7 +412,7 @@ def alert_rule_detail(rule_id: int, request: Request, user=Depends(require_user)
rule.get("name", "") or "Alert pravidlo",
f"""
<div class="card">
<h2>{html.escape(rule.get("name", "") or "")}</h2>
<h2><i class="fa-solid fa-bell" aria-hidden="true"></i> {html.escape(rule.get("name", "") or "")}</h2>
<p>
<a class="btn" href="/portal/alerting/rules">&larr; Zpět na alert pravidla</a>
<a class="btn btn-secondary" href="/portal/alerting/rules/{rule_id}/edit">Upravit</a>
@@ -469,7 +474,7 @@ def edit_alert_rule_form(rule_id: int, request: Request, user=Depends(require_us
"Upravit alert pravidlo",
f"""
<div class="card">
<h2>Upravit alert pravidlo</h2>
<h2><i class="fa-solid fa-pen-to-square" aria-hidden="true"></i> Upravit alert pravidlo</h2>
<p><a class="btn" href="/portal/alerting/rules/{rule_id}">&larr; Zpět</a></p>
</div>
<div class="card">
@@ -530,6 +535,12 @@ def delete_alert_rule_action(rule_id: int, user=Depends(require_user)):
raise HTTPException(status_code=404, detail="Alert pravidlo nenalezeno")
if not delete_alert_rule(rule_id):
raise HTTPException(status_code=409, detail="Alert pravidlo nelze smazat")
script_name = clean_optional(rule.get("script_name"))
if script_name:
path = script_path(script_name)
if path.exists():
path.unlink()
commit_and_push(f"alerts/{script_name}", f"Smazán alert skript {script_name}", user)
log_audit_event(
user,
action="alert_rule.deleted",
@@ -549,6 +560,7 @@ def update_alert_script(rule_id: int, content: str = Form(...), user=Depends(req
raise HTTPException(status_code=404, detail="Alert pravidlo nenalezeno")
script_name = validate_script_name(rule.get("script_name", "") or "")
save_script_file(script_name, content)
commit_and_push(f"alerts/{script_name}", f"Úprava alert skriptu {script_name}", user)
log_audit_event(
user,
action="alert_script.updated",
@@ -566,7 +578,7 @@ def alert_events_page(request: Request, user=Depends(require_user)):
"Alert eventy",
f"""
<div class="card">
<h2>Alert eventy</h2>
<h2><i class="fa-solid fa-bell-concierge" aria-hidden="true"></i> Alert eventy</h2>
<p class="muted">Historie vyvolaných alertů a jejich zpracování.</p>
<p><a class="btn" href="/portal/alerting/rules">Alert pravidla</a></p>
</div>
@@ -617,7 +629,7 @@ def alert_event_detail(event_id: int, request: Request, user=Depends(require_use
f"Alert event #{event_id}",
f"""
<div class="card">
<h2>Alert event #{html.escape(str(event_id))}</h2>
<h2><i class="fa-solid fa-bell-concierge" aria-hidden="true"></i> Alert event #{html.escape(str(event_id))}</h2>
<p>
<a class="btn" href="/portal/alerting/events">&larr; Zpět na alert eventy</a>
<a class="btn btn-secondary" href="/portal/alerting/rules">Alert pravidla</a>