mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 19:12:03 +03:00
exporter: name the report after the target, not always the local egress asn
target mode's filename fell back to the local machine's egress asn unconditionally, so 'netcheck --target AS15169' wrote report_<local-asn>_* instead of report_AS15169_*. meta.target already carries the right subject when one was given; prefer it and fall back to the egress asn only in auto mode.
This commit is contained in:
parent
3425e87dbf
commit
bfe9529667
2 changed files with 10 additions and 2 deletions
|
|
@ -89,8 +89,9 @@ def egress_asn(report: dict[str, Any]) -> str | None:
|
||||||
|
|
||||||
|
|
||||||
def write_report(report: dict[str, Any], markdown: str, logs_dir: Path) -> tuple[Path, Path]:
|
def write_report(report: dict[str, Any], markdown: str, logs_dir: Path) -> tuple[Path, Path]:
|
||||||
started = (report.get("meta") or {}).get("started_at", "")
|
meta = report.get("meta") or {}
|
||||||
asn = egress_asn(report)
|
started = meta.get("started_at", "")
|
||||||
|
asn = meta.get("target") or egress_asn(report)
|
||||||
base = Path(logs_dir)
|
base = Path(logs_dir)
|
||||||
json_path = atomic_write(base / report_filename(asn, started, "json"), dump_json(report))
|
json_path = atomic_write(base / report_filename(asn, started, "json"), dump_json(report))
|
||||||
md_path = atomic_write(base / report_filename(asn, started, "md"), markdown)
|
md_path = atomic_write(base / report_filename(asn, started, "md"), markdown)
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,13 @@ def test_egress_asn_is_read_out_of_the_assembled_report():
|
||||||
assert egress_asn({}) is None
|
assert egress_asn({}) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_write_report_names_the_file_after_the_target_in_target_mode(tmp_path: Path):
|
||||||
|
report = build_report({**meta(), "mode": "target", "target": "AS15169"}, modules(), [], {})
|
||||||
|
json_path, md_path = write_report(report, "# netcheck report\n", tmp_path)
|
||||||
|
assert json_path.name == "report_AS15169_20260808T191200Z.json"
|
||||||
|
assert md_path.name == "report_AS15169_20260808T191200Z.md"
|
||||||
|
|
||||||
|
|
||||||
def test_atomic_write_creates_the_directory_and_leaves_no_temp_file(tmp_path: Path):
|
def test_atomic_write_creates_the_directory_and_leaves_no_temp_file(tmp_path: Path):
|
||||||
target = tmp_path / "logs" / "report.json"
|
target = tmp_path / "logs" / "report.json"
|
||||||
atomic_write(target, '{"a": 1}')
|
atomic_write(target, '{"a": 1}')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue