Files
FabledSteward/steward/migrations/versions/0048_tickets.py
T
bvandeusenandClaude Opus 5.5 2a561210c3
CI / lint (push) Successful in 2s
CI / unit (push) Successful in 1m37s
CI / integration (push) Successful in 1m51s
CI / publish (push) Successful in 1m16s
feat(tickets): open, comment and resolve tickets from the UI and MCP; known issues on alerts and anomalies (#6351, #6352)
A ticket records a known problem: title, area, hosts, subject, description,
links to alert rules and anomalies, and a log of comments, edits, resolving
and reopening. Opening, resolving (with the resolution as the note) and
reopening go on the timeline; every step is audited, and the audit rows stay
off the timeline.

An alert or anomaly an open ticket covers (by link, by subject, or a
host-wide ticket on the host itself) shows a Known issue badge, and offers
"Open a ticket" prefilled from its rule or anomaly when none does. Hosts,
monitors and containers get a Known issues card.

MCP: list_tickets, get_ticket (viewer); open_ticket, update_ticket,
comment_ticket, resolve_ticket, reopen_ticket (operator). list_alerts and
list_anomalies carry known_issue; get_overview, get_host, get_monitor and
get_container carry open_tickets. Also update_change and delete_change for
changes recorded by hand (author or admin).

Tickets are left out of backups, like the timeline (2026-10-15 ruling).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 22:06:43 -04:00

63 lines
2.7 KiB
Python

"""Tickets: known problems, their links to alert rules and anomalies, and their log.
Revision ID: 0048_tickets
Revises: 0047_timeline
Create Date: 2026-10-25
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import ARRAY
revision: str = "0048_tickets"
down_revision: Union[str, None] = "0047_timeline"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"tickets",
sa.Column("id", sa.Integer, primary_key=True, autoincrement=True),
sa.Column("title", sa.String(200), nullable=False),
sa.Column("body", sa.Text, nullable=True),
sa.Column("area", sa.String(32), nullable=False),
sa.Column("hosts", ARRAY(sa.String(128)), nullable=False, server_default="{}"),
sa.Column("subject", sa.String(255), nullable=True),
sa.Column("status", sa.String(16), nullable=False, server_default="open"),
sa.Column("opened_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("opened_by", sa.String(64), nullable=False),
sa.Column("opened_by_id", sa.String(36), nullable=True),
sa.Column("resolved_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("resolved_by", sa.String(64), nullable=True),
sa.Column("resolution", sa.Text, nullable=True),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
)
op.create_index("ix_tickets_status", "tickets", ["status", "updated_at"])
op.create_index("ix_tickets_hosts", "tickets", ["hosts"], postgresql_using="gin")
op.create_table(
"ticket_links",
sa.Column("ticket_id", sa.Integer, sa.ForeignKey("tickets.id", ondelete="CASCADE"),
primary_key=True),
sa.Column("ref_type", sa.String(32), primary_key=True),
sa.Column("ref_id", sa.String(64), primary_key=True),
)
op.create_index("ix_ticket_links_ref", "ticket_links", ["ref_type", "ref_id"])
op.create_table(
"ticket_notes",
sa.Column("id", sa.String(36), primary_key=True),
sa.Column("ticket_id", sa.Integer, sa.ForeignKey("tickets.id", ondelete="CASCADE"),
nullable=False),
sa.Column("at", sa.DateTime(timezone=True), nullable=False),
sa.Column("kind", sa.String(16), nullable=False),
sa.Column("actor", sa.String(64), nullable=False),
sa.Column("body", sa.Text, nullable=True),
)
op.create_index("ix_ticket_notes_ticket", "ticket_notes", ["ticket_id", "at"])
def downgrade() -> None:
op.drop_table("ticket_notes")
op.drop_table("ticket_links")
op.drop_table("tickets")