Skip to content

reports

reports

API router for multi-device reporting.

create_report(request) async

Create a multi-device report.

Source code in hier_config_api/routers/reports.py
@router.post("", response_model=CreateReportResponse)
async def create_report(request: CreateReportRequest) -> CreateReportResponse:
    """Create a multi-device report."""
    try:
        report_data = ReportService.create_report(request.remediations)
        report_id = storage.store_report(report_data)

        return CreateReportResponse(report_id=report_id, total_devices=report_data["total_devices"])
    except Exception as e:
        raise HTTPException(status_code=400, detail=f"Failed to create report: {str(e)}") from e

get_report_summary(report_id) async

Get summary statistics for a report.

Source code in hier_config_api/routers/reports.py
@router.get("/{report_id}/summary", response_model=ReportSummary)
async def get_report_summary(report_id: str) -> ReportSummary:
    """Get summary statistics for a report."""
    report_data = storage.get_report(report_id)
    if not report_data:
        raise HTTPException(status_code=404, detail="Report not found")

    try:
        return ReportService.get_summary(report_data)
    except Exception as e:
        raise HTTPException(
            status_code=400, detail=f"Failed to get report summary: {str(e)}"
        ) from e

get_report_changes(report_id, tag=Query(None), min_devices=Query(1)) async

Get detailed change analysis for a report.

Source code in hier_config_api/routers/reports.py
@router.get("/{report_id}/changes", response_model=GetReportChangesResponse)
async def get_report_changes(
    report_id: str, tag: str | None = Query(None), min_devices: int = Query(1)
) -> GetReportChangesResponse:
    """Get detailed change analysis for a report."""
    report_data = storage.get_report(report_id)
    if not report_data:
        raise HTTPException(status_code=404, detail="Report not found")

    try:
        changes = ReportService.get_changes(report_data, tag_filter=tag, min_devices=min_devices)

        return GetReportChangesResponse(
            report_id=report_id, changes=changes, total_unique_changes=len(changes)
        )
    except Exception as e:
        raise HTTPException(
            status_code=400, detail=f"Failed to get report changes: {str(e)}"
        ) from e

export_report(report_id, format=Query('json')) async

Export report in specified format (json, csv, yaml).

Source code in hier_config_api/routers/reports.py
@router.get("/{report_id}/export", response_class=PlainTextResponse)
async def export_report(report_id: str, format: str = Query("json")) -> str:
    """Export report in specified format (json, csv, yaml)."""
    report_data = storage.get_report(report_id)
    if not report_data:
        raise HTTPException(status_code=404, detail="Report not found")

    if format not in ["json", "csv", "yaml"]:
        raise HTTPException(status_code=400, detail="Format must be one of: json, csv, yaml")

    try:
        return ReportService.export_report(report_data, format_type=format)
    except Exception as e:
        raise HTTPException(status_code=400, detail=f"Failed to export report: {str(e)}") from e