Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions check_docker/check_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,19 @@ def check_cpu(container, thresholds):
min=0, max=max)


def check_no_running():
"""Check if any containers are running."""

containers = get_containers('all', True)
running_containers = [c for c in containers if get_container_info(c)['State']['Running']]

if running_containers:
container_names = ', '.join(c for c in running_containers)
critical(f"Running containers detected: {container_names}")
else:
ok("No containers are running.")


def process_args(args):
parser = argparse.ArgumentParser(description='Check docker containers.')

Expand Down Expand Up @@ -752,6 +765,12 @@ def process_args(args):
action='store_true',
help='Modifies --containers so that each RegEx must match at least one container.')

# No running containers
parser.add_argument('--no-running',
dest='no_running',
action='store_true',
help='Check that no containers are running.')

# Threads
parser.add_argument('--threads',
dest='threads',
Expand Down Expand Up @@ -935,6 +954,9 @@ def perform_checks(raw_args):

# Here is where all the work happens
#############################################################################################
if args.no_running:
check_no_running()

containers = get_containers(args.containers, args.present)

if len(containers) == 0 and not args.present:
Expand Down