Internal Flask app that monitors the epi-helpdesk.zammad.com tickets via the Zammad API, deployable as a systemd service behind Apache under /episupport. Features: - Poller: session-login API sync, snapshot diff to detect agent changes (status, owner, priority, closures, new replies); email notifications - Dashboard: ticket overview with sorting, "not closed" filter and highlighting of tickets with unconfirmed changes; per-item and bulk "mark as read" - Analytics: KPIs, response/resolution times, monthly SVG trend chart, distributions (status/priority/group/agent), Excel export - Conversation view: full per-ticket thread cached in the DB (avoids proxy timeouts), inline image attachments, safe HTML-to-text rendering - Write actions: reply to tickets and create new tickets with a confirmation step and attachment upload (incl. clipboard paste); self-triggered actions are synced back so they aren't flagged as changes - Local timezone display (Europe/Berlin) for all timestamps Includes deploy tooling: setup.sh, systemd units and Apache config. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
106 lines
2.9 KiB
Python
106 lines
2.9 KiB
Python
"""SQLite-Zugriff: Schema, Verbindung, Hilfsfunktionen.
|
|
|
|
Die Datenbank wird vom Poller-Dienst geschrieben und vom Web-Dienst gelesen.
|
|
WAL-Modus erlaubt gleichzeitiges Lesen/Schreiben ohne Sperrkonflikte.
|
|
"""
|
|
import sqlite3
|
|
from contextlib import contextmanager
|
|
|
|
from . import config
|
|
|
|
SCHEMA = """
|
|
CREATE TABLE IF NOT EXISTS tickets (
|
|
id INTEGER PRIMARY KEY,
|
|
number TEXT,
|
|
title TEXT,
|
|
state TEXT,
|
|
state_id INTEGER,
|
|
priority TEXT,
|
|
priority_id INTEGER,
|
|
owner TEXT,
|
|
owner_id INTEGER,
|
|
"group" TEXT,
|
|
customer TEXT,
|
|
article_count INTEGER,
|
|
zammad_created_at TEXT,
|
|
zammad_updated_at TEXT,
|
|
last_contact_at TEXT,
|
|
last_contact_agent_at TEXT,
|
|
last_contact_customer_at TEXT,
|
|
close_at TEXT,
|
|
last_close_at TEXT,
|
|
raw_json TEXT,
|
|
first_seen_at TEXT,
|
|
last_synced_at TEXT
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS changes (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
ticket_id INTEGER NOT NULL,
|
|
ticket_number TEXT,
|
|
ticket_title TEXT,
|
|
field TEXT NOT NULL,
|
|
label TEXT,
|
|
old_value TEXT,
|
|
new_value TEXT,
|
|
detail TEXT,
|
|
detected_at TEXT NOT NULL,
|
|
seen INTEGER NOT NULL DEFAULT 0,
|
|
notified INTEGER NOT NULL DEFAULT 0
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_changes_detected ON changes(detected_at DESC);
|
|
CREATE INDEX IF NOT EXISTS idx_changes_ticket ON changes(ticket_id);
|
|
CREATE INDEX IF NOT EXISTS idx_changes_seen ON changes(seen);
|
|
|
|
CREATE TABLE IF NOT EXISTS articles (
|
|
article_id INTEGER PRIMARY KEY,
|
|
ticket_id INTEGER NOT NULL,
|
|
sender TEXT,
|
|
frm TEXT,
|
|
subject TEXT,
|
|
body TEXT,
|
|
content_type TEXT,
|
|
internal INTEGER,
|
|
created_at TEXT,
|
|
attachments TEXT,
|
|
fetched_at TEXT
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_articles_ticket ON articles(ticket_id, created_at);
|
|
|
|
CREATE TABLE IF NOT EXISTS sync_runs (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
started_at TEXT,
|
|
finished_at TEXT,
|
|
ticket_count INTEGER,
|
|
change_count INTEGER,
|
|
status TEXT,
|
|
error TEXT
|
|
);
|
|
"""
|
|
|
|
|
|
def connect() -> sqlite3.Connection:
|
|
conn = sqlite3.connect(config.DB_PATH, timeout=30)
|
|
conn.row_factory = sqlite3.Row
|
|
conn.execute("PRAGMA journal_mode=WAL;")
|
|
conn.execute("PRAGMA busy_timeout=10000;")
|
|
conn.execute("PRAGMA foreign_keys=ON;")
|
|
return conn
|
|
|
|
|
|
@contextmanager
|
|
def get_conn():
|
|
conn = connect()
|
|
try:
|
|
yield conn
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def init_db() -> None:
|
|
with get_conn() as conn:
|
|
conn.executescript(SCHEMA)
|