Skip to content

Commit 84ef3df

Browse files
committed
health_service
1 parent 84a936b commit 84ef3df

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

actions/health_service.py

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

actions/health_service.yaml

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

0 commit comments

Comments
 (0)