From 10883847b5ebcb37d3299f712ac2a8a8cc307e5a Mon Sep 17 00:00:00 2001 From: Grigory Bazilevich Date: Wed, 5 Mar 2025 12:57:52 +0300 Subject: feat: short diff report in csv format --- main.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index e6c39aa..41decc6 100644 --- a/main.py +++ b/main.py @@ -50,6 +50,8 @@ def manager_write_state(mgr, method, new_state): file = os.path.join(dir, f"{method}.state") if not os.path.exists(file): os.close(os.open(file, os.O_CREAT)) + with open(os.path.join(dir, f"{method}.diff"), "w") as f: + f.write("time,not_changed,new,removed\n") old_state = [] with open(file, "r") as f: @@ -63,15 +65,9 @@ def manager_write_state(mgr, method, new_state): file = os.path.join(dir, f"{method}.diff") time = datetime.now().isoformat() with open(file, "a") as f: - f.write("Time: {}\n\n".format(time)) - if len(diff["not_changed"]) != 0: - f.write("Not changed: {}\n".format(len(diff["not_changed"]))) - if len(diff["new"]) != 0: - f.write("New: {}\n".format(len(diff["new"]))) - if len(diff["removed"]) != 0: - f.write("Removed: {}\n".format(len(diff["removed"]))) - - f.write("===\n") + f.write( + f"{time},{len(diff['not_changed'])},{len(diff['new'])},{len(diff['removed'])}\n" + ) file = f"{file}.detail" with open(file, "a") as f: @@ -148,7 +144,9 @@ def main(): try: data = do_get(manager["http_url"], endpoint["http_uri"]) except Exception as e: - print(f"Failed to get information from manager {manager['name']} using endpoint {endpoint['name']}") + print( + f"Failed to get information from manager {manager['name']} using endpoint {endpoint['name']}" + ) print(e) continue @@ -159,13 +157,17 @@ def main(): data = parse_crashes(manager["name"], data) state = data.split("\n") except: - print(f"Failed to parse information from manager {manager['name']}, endpoint: {endpoint['name']}") + print( + f"Failed to parse information from manager {manager['name']}, endpoint: {endpoint['name']}" + ) continue try: manager_write_state(manager["name"], endpoint["name"], state) except: - print(f"Failed to log manager {manager['name']} state, endpoint: {endpoint['name']}") + print( + f"Failed to log manager {manager['name']} state, endpoint: {endpoint['name']}" + ) continue time.sleep(config["timeout"]) -- cgit mrf-deployment