|
|
|
|
@ -163,6 +163,20 @@ def api_reports_create():
|
|
|
|
|
return {"id": r.id}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main_bp.route("/api/reports/<int:report_id>", methods=["DELETE"])
|
|
|
|
|
@login_required
|
|
|
|
|
def api_reports_delete(report_id: int):
|
|
|
|
|
err = _require_reporting_role()
|
|
|
|
|
if err is not None:
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
|
|
report = ReportDefinition.query.get_or_404(report_id)
|
|
|
|
|
db.session.delete(report)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main_bp.route("/api/reports/<int:report_id>/generate", methods=["POST"])
|
|
|
|
|
@login_required
|
|
|
|
|
def api_reports_generate(report_id: int):
|
|
|
|
|
@ -191,39 +205,37 @@ def api_reports_generate(report_id: int):
|
|
|
|
|
where_customer = ""
|
|
|
|
|
params = {"rid": report_id, "start_ts": report.period_start, "end_ts": report.period_end}
|
|
|
|
|
if scope in ("single", "multiple") and customer_ids:
|
|
|
|
|
where_customer = " AND c.id = ANY(:customer_ids) "
|
|
|
|
|
where_customer = " AND j.customer_id = ANY(:customer_ids) "
|
|
|
|
|
params["customer_ids"] = customer_ids
|
|
|
|
|
|
|
|
|
|
db.session.execute(
|
|
|
|
|
text(
|
|
|
|
|
f'''
|
|
|
|
|
INSERT INTO report_object_snapshots
|
|
|
|
|
INSERT INTO report_object_snapshots
|
|
|
|
|
(report_id, object_name, job_id, job_name, customer_id, customer_name,
|
|
|
|
|
backup_software, backup_type, run_id, run_at, status, missed,
|
|
|
|
|
override_applied, reviewed_at, ticket_number, remark, created_at)
|
|
|
|
|
SELECT
|
|
|
|
|
:rid AS report_id,
|
|
|
|
|
co.object_name AS object_name,
|
|
|
|
|
COALESCE(j.job_name, '(unknown job)') AS object_name,
|
|
|
|
|
j.id AS job_id,
|
|
|
|
|
j.job_name AS job_name,
|
|
|
|
|
c.id AS customer_id,
|
|
|
|
|
j.customer_id AS customer_id,
|
|
|
|
|
c.name AS customer_name,
|
|
|
|
|
j.backup_software AS backup_software,
|
|
|
|
|
j.backup_type AS backup_type,
|
|
|
|
|
jr.id AS run_id,
|
|
|
|
|
jr.run_at AS run_at,
|
|
|
|
|
COALESCE(rol.status, jr.status) AS status,
|
|
|
|
|
jr.status AS status,
|
|
|
|
|
COALESCE(jr.missed, FALSE) AS missed,
|
|
|
|
|
COALESCE(jr.override_applied, FALSE) AS override_applied,
|
|
|
|
|
jr.reviewed_at AS reviewed_at,
|
|
|
|
|
NULL AS ticket_number,
|
|
|
|
|
jr.remark AS remark,
|
|
|
|
|
NOW() AS created_at
|
|
|
|
|
FROM run_object_links rol
|
|
|
|
|
JOIN customer_objects co ON co.id = rol.customer_object_id
|
|
|
|
|
JOIN customers c ON c.id = co.customer_id
|
|
|
|
|
JOIN job_runs jr ON jr.id = rol.run_id
|
|
|
|
|
FROM job_runs jr
|
|
|
|
|
JOIN jobs j ON j.id = jr.job_id
|
|
|
|
|
LEFT JOIN customers c ON c.id = j.customer_id
|
|
|
|
|
WHERE jr.run_at IS NOT NULL
|
|
|
|
|
AND jr.run_at >= :start_ts
|
|
|
|
|
AND jr.run_at < :end_ts
|
|
|
|
|
@ -242,7 +254,7 @@ def api_reports_generate(report_id: int):
|
|
|
|
|
warning_count, failed_count, missed_count, success_rate, created_at)
|
|
|
|
|
SELECT
|
|
|
|
|
:rid AS report_id,
|
|
|
|
|
s.object_name AS object_name,
|
|
|
|
|
COALESCE(s.job_name, '(unknown job)') AS object_name,
|
|
|
|
|
COUNT(*)::INTEGER AS total_runs,
|
|
|
|
|
SUM(CASE WHEN (COALESCE(s.status,'') ILIKE 'success%' AND s.override_applied = FALSE) THEN 1 ELSE 0 END)::INTEGER AS success_count,
|
|
|
|
|
SUM(CASE WHEN (s.override_applied = TRUE) THEN 1 ELSE 0 END)::INTEGER AS success_override_count,
|
|
|
|
|
@ -261,7 +273,7 @@ def api_reports_generate(report_id: int):
|
|
|
|
|
NOW() AS created_at
|
|
|
|
|
FROM report_object_snapshots s
|
|
|
|
|
WHERE s.report_id = :rid
|
|
|
|
|
GROUP BY s.object_name
|
|
|
|
|
GROUP BY s.job_id, s.job_name
|
|
|
|
|
'''
|
|
|
|
|
),
|
|
|
|
|
{"rid": report_id},
|
|
|
|
|
|