This commit is contained in:
vvzvlad 2024-11-24 02:51:12 +03:00
parent 90aa23cf63
commit 727e13bbab

View File

@ -1,3 +1,8 @@
# flake8: noqa
# pylint: disable=broad-exception-raised, raise-missing-from, too-many-arguments, redefined-outer-name
# pylance: disable=reportMissingImports, reportMissingModuleSource, reportGeneralTypeIssues
# type: ignore
import re
from datetime import datetime, timedelta, timezone
import subprocess
@ -6,6 +11,7 @@ import time
import random
import sys
import pkg_resources
import requests
required_packages = ['grist-api', 'colorama']
installed_packages = [pkg.key for pkg in pkg_resources.working_set]
@ -16,7 +22,7 @@ for package in required_packages:
from grist_api import GristDocAPI
import colorama
import requests
import logging
import socket
@ -88,40 +94,40 @@ class GRIST:
raise ValueError(f"Setting {key} not found")
def check_logs(logger):
def check_logs(log_handler):
# Initialize counters
error_count = 0
sync_count = 0
total_challenges = 0
try:
result = subprocess.run(['docker', 'compose', 'logs', '--since', '24h'], cwd='/root/node/', capture_output=True, text=True)
log_content = result.stdout
logs = subprocess.run(['docker', 'compose', 'logs', '--since', '24h'], cwd='/root/node/', capture_output=True, text=True, check=True)
log_content = logs.stdout
except subprocess.CalledProcessError as e:
raise Exception(f"Error running docker compose logs: {e}")
raise RuntimeError(f"Error running docker compose logs: {e}") from e
for line in log_content.split('\n'):
if "Error from tendermint rpc" in line:
error_count += 1
logger.error(f"RPC error: {line}")
log_handler.error(f"RPC error: {line}")
if "Is your verifier's account funded" in line:
logger.error(f"Verifier account not funded: {line}")
log_handler.error(f"Verifier account not funded: {line}")
error_count += 1
if "Synced with network" in line:
sync_count += 1
logger.info(f"Synced with network: {line}")
log_handler.info(f"Synced with network: {line}")
challenge_match = re.search(r'made (\d+) secret challenges', line)
if challenge_match:
total_challenges += int(challenge_match.group(1))
logger.info(f"Made {total_challenges} secret challenges: {line}")
result = {
log_handler.info(f"Made {total_challenges} secret challenges: {line}")
data = {
"errors": error_count,
"sync_events": sync_count,
"total_challenges": total_challenges
}
logger.info(f"Result: {result}")
return result
log_handler.info(f"Result: {data}")
return data
if __name__ == "__main__":
print("Checker started")