Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to exclude specific containers #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 14 additions & 2 deletions check_docker/check_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,14 @@ def get_ps_name(name_list):
raise NameError("Error when trying to identify 'ps' name in {}".format(name_list))


def get_containers(names, require_present):
def get_containers(names, require_present, exclude_containers):
containers_list, _ = get_url(daemon + '/containers/json?all=1')

all_container_names = set(get_ps_name(x['Names']) for x in containers_list)

if exclude_containers:
all_container_names = all_container_names.difference(exclude_containers)

if 'all' in names:
return all_container_names

Expand Down Expand Up @@ -745,6 +748,15 @@ def process_args(args):
default=['all'],
help='One or more RegEx that match the names of the container(s) to check. If omitted all containers are checked. (default: %(default)s)')

# Exclude container name
parser.add_argument('--exclude_containers',
dest='exclude_containers',
action='store',
nargs='+',
type=str,
default=[],
help='One or more containers to ignore. If omitted all containers are checked.')

# Container name
parser.add_argument('--present',
dest='present',
Expand Down Expand Up @@ -935,7 +947,7 @@ def perform_checks(raw_args):

# Here is where all the work happens
#############################################################################################
containers = get_containers(args.containers, args.present)
containers = get_containers(args.containers, args.present, args.exclude_containers)

if len(containers) == 0 and not args.present:
unknown("No containers names found matching criteria")
Expand Down