Skip to content

Commit f5784c6

Browse files
authored
Merge pull request #5 from nullkarma/master
Added Health Service and Check Action
2 parents 84a936b + f9032d8 commit f5784c6

File tree

6 files changed

+62
-1
lines changed

6 files changed

+62
-1
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 0.4.0
4+
5+
- Added consul.health_service action to query a services status and group the result by hostname
6+
- Added consul.health_check action to query a services status and group the result by check
7+
38
## 0.3.0
49

510
- Added consul.list action to get a list of Keys from consul under a given <root> key

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+

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

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
ref: consul
44
name: consul
55
description: consul
6-
version: 0.3.0
6+
version: 0.4.0
77
author: jfryman
88

0 commit comments

Comments
 (0)