Skip to content

Commit

Permalink
Merge pull request #89 from pyouroboros/healthchecks-webhook
Browse files Browse the repository at this point in the history
add keep_alive url for healthchecks. Addresses half of #80
  • Loading branch information
dirtycajunrice authored Jan 13, 2019
2 parents dd0864a + 8ca5e7d commit 0e248a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 4 additions & 1 deletion pyouroboros/dockerclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ def update_containers(self):
self.data_manager.add(label='all', socket=self.socket)

if updated_count > 0:
self.notification_manager.send(container_tuples=updated_container_tuples, socket=self.socket)
self.notification_manager.send(container_tuples=updated_container_tuples, socket=self.socket,
notification_type='data')

self.notification_manager.send(notification_type='keep_alive')
20 changes: 13 additions & 7 deletions pyouroboros/notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ def __init__(self, config, data_manager):
self.data_manager = data_manager
self.logger = getLogger()

def send(self, container_tuples, socket):
def send(self, container_tuples=None, socket=None, notification_type='data'):
formatted_webhooks = []
if self.config.webhook_urls:
for webhook_url in self.config.webhook_urls:
if 'discord' in webhook_url:
format_type = 'discord'
elif 'slack' in webhook_url:
format_type = 'slack'
if notification_type == "keep_alive":
if "hc-ping" in webhook_url:
formatted_webhooks.append((webhook_url, {}))
else:
format_type = 'default'
if 'discord' in webhook_url:
format_type = 'discord'
elif 'slack' in webhook_url:
format_type = 'slack'
elif 'hc-ping' in webhook_url:
continue
else:
format_type = 'default'

formatted_webhooks.append((webhook_url, self.format(container_tuples, socket, format_type)))
formatted_webhooks.append((webhook_url, self.format(container_tuples, socket, format_type)))

self.post(formatted_webhooks)

Expand Down

0 comments on commit 0e248a5

Please sign in to comment.