From 64d5785f4acd2c719b9aad1f7e5a815c1ba3ee57 Mon Sep 17 00:00:00 2001 From: ezkrg Date: Tue, 29 Sep 2020 12:49:36 +0200 Subject: [PATCH 1/2] fix ignore_paused --- check_docker/check_swarm.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/check_docker/check_swarm.py b/check_docker/check_swarm.py index 106fa4a..f6c3cf2 100755 --- a/check_docker/check_swarm.py +++ b/check_docker/check_swarm.py @@ -178,7 +178,7 @@ def check_swarm(): def process_global_service(name, ignore_paused=False): bad_node_states = {'drain'} if ignore_paused: - bad_node_states.add('paused') + bad_node_states.add('pause') # Get all the nodes we care about based on their state node_list, status = get_nodes() @@ -193,13 +193,12 @@ def process_global_service(name, ignore_paused=False): # Also note, this ignores conditions where services state they are running on a node not in the index. service_tasks = get_service_tasks(name) for task in service_tasks: - if task['Status']['State'] != 'running': - critical('Global service {service} has one or more tasks not running'.format(service=name)) - return - node_index.discard(task['NodeID']) + if task['Status']['State'] == 'running' and task['NodeID'] in node_index: + node_index.discard(task['NodeID']) if len(node_index) > 0: critical('Global service {service} has {count} tasks not running'.format(service=name, count=len(node_list))) + return ok('Global service {service} OK'.format(service=name)) @@ -266,6 +265,11 @@ def process_args(args): default=DEFAULT_TIMEOUT, help='Connection timeout in seconds. (default: %(default)s)') + parser.add_argument('--ignore_paused', + dest='ignore_paused', + action='store_true', + help="Don't require global services to be running on paused nodes") + swarm_group = parser.add_mutually_exclusive_group(required=True) # Swarm @@ -284,11 +288,6 @@ def process_args(args): default=[], help='One or more RegEx that match the names of the services(s) to check.') - swarm_group.add_argument('--ignore_paused', - dest='ignore_paused', - action='store_true', - help="Don't require global services to be running on paused nodes") - parser.add_argument('-V', action='version', version='%(prog)s {}'.format(__version__)) if len(args) == 0: From 6768fd119cab3cd73a2b4a876f15fb05fdf86738 Mon Sep 17 00:00:00 2001 From: ezkrg Date: Tue, 29 Sep 2020 15:05:05 +0200 Subject: [PATCH 2/2] fix error count --- check_docker/check_swarm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_docker/check_swarm.py b/check_docker/check_swarm.py index f6c3cf2..094db47 100755 --- a/check_docker/check_swarm.py +++ b/check_docker/check_swarm.py @@ -197,7 +197,7 @@ def process_global_service(name, ignore_paused=False): node_index.discard(task['NodeID']) if len(node_index) > 0: - critical('Global service {service} has {count} tasks not running'.format(service=name, count=len(node_list))) + critical('Global service {service} has {count} tasks not running'.format(service=name, count=len(node_index))) return ok('Global service {service} OK'.format(service=name))