Skip to content

Commit

Permalink
Post events to Datadog
Browse files Browse the repository at this point in the history
  • Loading branch information
aknuds1 committed Jan 5, 2016
1 parent 436650b commit e7f0384
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
rethinkdb
boto3
datadog
16 changes: 16 additions & 0 deletions schedule-rethinkdb-backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import contextlib
import time
import datadog.api

from backup_rethinkdb import backup_rethinkdb, get_environment_value

Expand Down Expand Up @@ -53,6 +54,10 @@ def _schedule_backup(loop):

def _backup(loop):
"""Perform actual backup."""
def post_datadog_event(title, text, alert_type):
datadog.api.Event.create(title=title, text=text, alert_type=alert_type)


success = False
for attempt in range(1, 4):
now = datetime.now()
Expand All @@ -72,14 +77,25 @@ def _backup(loop):
break
if success:
_logger.info('Backed up successfully!')
post_datadog_event(
'RethinkDB Backup Success',
'RethinkDB was successfully backed up', 'info')
else:
_logger.error('Failed to back up!')
post_datadog_event(
'RethinkDB Backup Failure',
'Failed to back up RethinkDB: {}'.format(err), 'error')

_logger.debug('Scheduling next backup')
_schedule_backup(loop)


def _main():
datadog.api.initialize(
api_key=get_environment_value('DATADOG_API_KEY'),
app_key=get_environment_value('DATADOG_APP_KEY')
)

with contextlib.closing(asyncio.get_event_loop()) as loop:
_schedule_backup(loop)
try:
Expand Down

0 comments on commit e7f0384

Please sign in to comment.