From e5a0eef02091ed6bc54d25166f3f04d76279f8a3 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sun, 19 Jan 2025 11:42:14 +0300 Subject: [PATCH] Enhance check_logs function in checker.py to capture last subscription ID from logs. Added logic to identify and return the most recent subscription ID when "Ignored subscription creation" messages are detected. This improves the clarity of log analysis by providing specific subscription status, while maintaining the existing error handling for Docker log retrieval. --- checker.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/checker.py b/checker.py index f2fbb4f..b7408d7 100644 --- a/checker.py +++ b/checker.py @@ -138,13 +138,20 @@ def check_logs(log_handler): try: logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True) log_content = clean_ansi(logs.stdout) + + last_subscription_id = None + for line in log_content.splitlines(): + if "Ignored subscription creation" in line and "id=" in line: + id_match = re.search(r'id=(\d+)', line) + if id_match: + last_subscription_id = id_match.group(1) + + if last_subscription_id: + return {"status": f"Subscription: {last_subscription_id}"} + return {"status": "Idle"} + except subprocess.CalledProcessError as e: raise RuntimeError(f"Error running docker logs: {e}") - - for line in log_content.splitlines(): - print(line) - - return {"status": "Idle"} if __name__ == "__main__":