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.
This commit is contained in:
parent
c95fce1b69
commit
e5a0eef020
17
checker.py
17
checker.py
@ -138,14 +138,21 @@ 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__":
|
||||
colorama.init(autoreset=True)
|
||||
|
Loading…
Reference in New Issue
Block a user