Add log_enhancer/src/log_enhancer/cli.py
This commit is contained in:
parent
5bb8763301
commit
b7029b9148
1 changed files with 53 additions and 0 deletions
53
log_enhancer/src/log_enhancer/cli.py
Normal file
53
log_enhancer/src/log_enhancer/cli.py
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Dict
|
||||||
|
import os
|
||||||
|
|
||||||
|
from log_enhancer.core import enhance_log_entries
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_file(path: Path, must_exist: bool = True) -> Path:
|
||||||
|
if must_exist and not path.exists():
|
||||||
|
raise FileNotFoundError(f"Datei nicht gefunden: {path}")
|
||||||
|
if must_exist and not path.is_file():
|
||||||
|
raise ValueError(f"Pfad ist keine Datei: {path}")
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description=(
|
||||||
|
"CLI-Tool zur Verbesserung von Logeinträgen durch Hinzufügen fehlender Artefaktinformationen."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zur Eingabedatei mit Roh-Logdaten im JSON-Format."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zur Ausgabedatei für angereicherte Logs."
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = _validate_file(Path(args.input))
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
with input_path.open("r", encoding="utf-8") as f:
|
||||||
|
log_data: List[Dict] = json.load(f)
|
||||||
|
|
||||||
|
assert isinstance(log_data, list), "Eingabedaten müssen eine Liste von Logeinträgen sein."
|
||||||
|
|
||||||
|
enhanced_logs = enhance_log_entries(log_data)
|
||||||
|
|
||||||
|
os.makedirs(output_path.parent, exist_ok=True)
|
||||||
|
with output_path.open("w", encoding="utf-8") as f:
|
||||||
|
json.dump(enhanced_logs, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue