Skip to content

Instantly share code, notes, and snippets.

@yankcrime
Last active October 7, 2020 16:23
Show Gist options
  • Save yankcrime/b29686a7ecbc07ea2445cdddea44a276 to your computer and use it in GitHub Desktop.
Save yankcrime/b29686a7ecbc07ea2445cdddea44a276 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
scanreport.py
Takes Rancher cis-operator ClusterScanReport JSON via stdin
and formats it in a table
Example usage:
$ kubectl get clusterscanreport scan-report-rke-cis-1.5-hardened \
-o jsonpath="{.spec.reportJSON}" | ~/tmp/scanreport.py
"""
import sys
import json
from prettytable import PrettyTable
data = json.load(sys.stdin)
resultsTable = PrettyTable()
summaryTable = PrettyTable()
resultsTable.field_names = ["ID", "Area", "Description", "Result"]
resultsTable.align = "l"
resultsTable.sortby = "ID"
for r in data["results"]:
for c in r["checks"]:
resultsTable.add_row(
[c["id"], r["description"], c["description"], c["state"]])
summaryTable.field_names = ["Total", "Pass", "Fail", "Skip", "N/A"]
summaryTable.align = "r"
summaryTable.add_row(
[data["total"], data["pass"], data["fail"],
data["skip"], data["notApplicable"]]
)
print(resultsTable)
print(summaryTable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment