Skip to content

Commit 5953d65

Browse files
committed
health_check
1 parent 84ef3df commit 5953d65

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

actions/health_check.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from lib import action
2+
from collections import defaultdict
3+
4+
5+
class ConsulCheckHealth(action.ConsulBaseAction):
6+
def run(self, service):
7+
index, nodes = self.consul.health.checks(service=service)
8+
s = defaultdict(dict)
9+
for node in nodes:
10+
try:
11+
s[node.get('CheckID')][node.get('Status')].append(node.get('Node'))
12+
except KeyError:
13+
s[node.get('CheckID')][node.get('Status')] = []
14+
s[node.get('CheckID')][node.get('Status')].append(node.get('Node'))
15+
return s

actions/health_check.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: health_check
2+
runner_type: run-python
3+
description: "Query health status of a check in consul"
4+
enabled: true
5+
entry_point: "health_check.py"
6+
parameters:
7+
service:
8+
type: string
9+
description: "Service to query in Consul"
10+
required: true
11+

0 commit comments

Comments
 (0)