Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion datadog_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import time
import subprocess

try:
import datadog
Expand Down Expand Up @@ -96,6 +97,18 @@ def _send_event(self, title, alert_type=None, text=None, tags=None, host=None, e
print('Couldn\'t send event "{0}" to Datadog'.format(title))
print(e)

def get_branch_info(self):
command = "git symbolic-ref --short HEAD"
try:
out = subprocess.check_output(command.split())
branch = out.decode().rstrip()
except Exception as e:
print('Couldn\'t find git branch information, sending None')
print(e)
branch = "None"

return branch

# Send event, aggregated with other task-level events from the same host
def send_task_event(self, title, alert_type='info', text='', tags=None, host=None):
if getattr(self, 'play', None):
Expand Down Expand Up @@ -151,7 +164,7 @@ def get_elapsed_time(self):
# Default tags sent with events and metrics
@property
def default_tags(self):
return ['playbook:{0}'.format(self._playbook_name)]
return ['playbook:{0}'.format(self._playbook_name), 'git-branch:{0}'.format(self.get_branch_info())]

@staticmethod
def pluralize(number, noun):
Expand Down