"""Sammelbericht über Postfächer, Teams, Graph-Einstellungen und SharePoint-Tenant (nur lokal, kein Netz). Liest die Zusammenfassungen der anderen Skripte und prüft alle JSON-Dateien auf Lesbarkeit. Schreibt report.json in den Zielordner.""" import glob, json, os, sys, time sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import m365_auth as auth def main(argv=None): p = auth.make_parser("Summary report over the backup areas (local only)") args = p.parse_args(argv) B = args.out R = {"created": time.strftime("%Y-%m-%d %H:%M:%S"), "areas": {}} # Postfächer z = json.load(open(os.path.join(B, "mailboxes/_summary.json"))) with_mb = [x for x in z if x.get("mailbox")]; without = [x for x in z if not x.get("mailbox")] n, b = auth.folder_size(os.path.join(B, "mailboxes")) R["areas"]["mailboxes"] = { "users_with_mailbox": len(with_mb), "users_without_mailbox": [{"upn": x["upn"], "status": x["status"]} for x in without], "messages": sum(x["messages"] for x in with_mb), "expected_totalItemCount": sum(x["expected"] for x in with_mb), "attachments": sum(x["attachments"] for x in with_mb), "events": sum(x["events"] for x in with_mb), "contacts": sum(x["contacts"] for x in with_mb), "files": n, "bytes": b, "errors": [{"upn": x["upn"], "errors": x["errors"]} for x in with_mb if x["errors"]], "per_user": [{"upn": x["upn"], "messages": x["messages"], "expected": x["expected"], "deviation": x["deviation"]} for x in with_mb]} # Teams tz = json.load(open(os.path.join(B, "teams/_summary.json"))); nmt = json.load(open(os.path.join(B, "teams/not_possible.json"))) n, b = auth.folder_size(os.path.join(B, "teams")) R["areas"]["teams"] = {**tz, "files": n, "bytes": b, "not_possible_count": len(nmt), "not_possible_status": sorted({str(v.get("status")) for v in nmt.values()}), "not_possible_example": list(nmt.items())[:3]} gz = json.load(open(os.path.join(B, "graph_settings/_summary.json"))); n, b = auth.folder_size(os.path.join(B, "graph_settings")) R["areas"]["graph_settings"] = {"ok_datasets": len(gz["ok"]), "objects_total": sum(gz["ok"].values()), "files": n, "bytes": b, "not_possible": gz["not_possible"]} sz = json.load(open(os.path.join(B, "spo_tenant/_summary.json"))); n, b = auth.folder_size(os.path.join(B, "spo_tenant")) R["areas"]["spo_tenant"] = {"ok": list(sz["ok"]), "files": n, "bytes": b, "not_possible": sz["not_possible"], "note": "GET REST only (SPO.Tenant, SiteProperties schema); CSOM ProcessQuery/POST deliberately not used (read-only rule)."} # JSON-Prüfung bad, cnt = [], 0 for d in ("mailboxes", "teams", "graph_settings", "spo_tenant"): for path in glob.glob(os.path.join(B, d, "**/*.json"), recursive=True): cnt += 1 try: json.load(open(path)) except Exception: bad.append(path) R["json_checked"] = cnt; R["json_broken"] = bad auth.write_json(os.path.join(B, "report.json"), R) print(cnt, bad[:5]) return 0 if __name__ == "__main__": sys.exit(main())