diff --git a/inspector/inspector_qbitt.py b/inspector/inspector_qbitt.py index 54920e2..5eb7bb6 100755 --- a/inspector/inspector_qbitt.py +++ b/inspector/inspector_qbitt.py @@ -24,6 +24,7 @@ if not os.path.exists(logs_folder): def get_log_file_path(): return os.path.join(logs_folder, 'inspector_qbitt.log') +# Rotate the log files at 12am daily def rotate_log_files(log_file): now = datetime.datetime.now() timestamp = now.strftime('%Y-%m-%d') @@ -35,17 +36,35 @@ def rotate_log_files(log_file): os.rename(log_file, rotated_log_path) +# Formating time def format_remaining_time(remaining_time): minutes, seconds = divmod(remaining_time.seconds, 60) return f'{minutes} minutes {seconds} seconds' +# Checking the health of the container def check_container_health(container_name): client = docker.from_env() - container = client.containers.get(container_name) - return container.attrs['State']['Health']['Status'].upper() + try: + container = client.containers.get(container_name) + # Check if container is running + if container.status != 'running': + return 'NOT RUNNING' + + health_data = container.attrs['State'].get('Health') + if health_data is None: + return 'NO HEALTH CHECK' + + health_status = health_data.get('Status', 'UNKNOWN') + return health_status.upper() + + except docker.errors.NotFound: + return 'CONTAINER NOT FOUND' + except Exception as e: + return f'ERROR: {str(e)}' +# Restaring the container def restart_container(container_name): client = docker.from_env() container = client.containers.get(container_name)