Inspector
> Updated the `check_container_health(container_name)` function. Included to check if container is running and any other exceptions. If it finds any of those the functions will return messages that are not "Healthy" which will trigger the error count. > Added comments to various functions
This commit is contained in:
parent
e46230de0b
commit
07b323010e
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user