34 lines
2.3 KiB
Python
34 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
from pathlib import Path
|
|
import psycopg2
|
|
|
|
PASS = Path("/root/.pg-superuser-pass").read_text().strip()
|
|
conn = psycopg2.connect(host="192.168.1.151", dbname="rag", user="postgres", password=PASS, client_encoding="UTF8")
|
|
cur = conn.cursor()
|
|
cur.execute("""create table if not exists audit.arena_runs(
|
|
id bigserial primary key, audit_run_id bigint, status text default 'running',
|
|
created_at timestamptz default now(), finished_at timestamptz, summary jsonb default '{}'::jsonb)""")
|
|
cur.execute("""create table if not exists audit.arena_answers(
|
|
id bigserial primary key, arena_run_id bigint references audit.arena_runs(id) on delete cascade,
|
|
voice text, model text, role text, answer jsonb, raw text, created_at timestamptz default now())""")
|
|
cur.execute("""create table if not exists audit.arena_items(
|
|
id bigserial primary key, arena_run_id bigint references audit.arena_runs(id) on delete cascade,
|
|
title text, capability text, voices text, impact int, effort int, risk int, score numeric,
|
|
evidence text, hypothesis text, first_step text, selected boolean default false)""")
|
|
conn.commit()
|
|
cur.execute("select id from audit.runs order by id desc limit 1")
|
|
audit_run_id = cur.fetchone()[0]
|
|
cur.execute("""select key,title,maturity,automation,leverage,criticality,evidence,gaps
|
|
from audit.capabilities where run_id=%s order by key""", (audit_run_id,))
|
|
caps = [dict(key=r[0],title=r[1],maturity=r[2],automation=r[3],leverage=r[4],criticality=r[5],evidence=r[6],gaps=r[7]) for r in cur.fetchall()]
|
|
cur.execute("select severity,area,title,evidence from audit.findings where run_id=%s order by id", (audit_run_id,))
|
|
findings = [dict(severity=r[0],area=r[1],title=r[2],evidence=r[3]) for r in cur.fetchall()]
|
|
cur.execute("select summary from audit.runs where id=%s", (audit_run_id,))
|
|
facts = (cur.fetchone() or [{}])[0]
|
|
packet = {"facts": (facts or {}).get("facts", {}), "capabilities": caps, "findings": findings}
|
|
Path("/root/buryan-infra/ops/audit/arena_packet.json").write_text(json.dumps(packet, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
cur.execute("insert into audit.arena_runs(audit_run_id,status) values(%s,'packet') returning id", (audit_run_id,))
|
|
print("arena run", cur.fetchone()[0], "packet bytes", len(json.dumps(packet, ensure_ascii=False)))
|
|
conn.commit(); cur.close(); conn.close()
|