Created
March 3, 2013 04:12
-
-
Save SEJeff/5074466 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Salt returner that report error back to sentry | |
Pillar need something like: | |
deployment: | |
sentry_dsn: foobar | |
and http://pypi.python.org/pypi/raven installed | |
""" | |
import logging | |
from raven import Client | |
logger = logging.getLogger(__name__) | |
def __virtual__(): | |
return 'sentry' | |
def connect_sentry(state): | |
pillar_data = __salt__['pillar.data']() | |
sentry_data = { | |
'state': state, | |
'pillar': pillar_data, | |
'grains': __salt__['grains.items']() | |
} | |
try: | |
client = Client(dsn=pillar_data['deployment']['sentry_dsn']) | |
client.captureMessage(state['comment'], extra=sentry_data) | |
except Exception as err: | |
logger.error("Can't send message to sentry: %s", err, | |
exc_info=True) | |
def returner(ret): | |
""" | |
If an error occurs, log it to sentry | |
""" | |
requisite_error = 'One or more requisite failed' | |
try: | |
if 'success' not in ret: | |
logger.debug("no success data, report") | |
connect_sentry(ret['return'], ret) | |
else: | |
if not ret['success']: | |
logger.debug("not a success, report") | |
connect_sentry(ret['return'], ret) | |
else: | |
for returned in ret['return'].values(): | |
if ( | |
not returned['result'] and | |
returned['comment'] != requisite_error | |
): | |
connect_sentry(returned) | |
except Exception, err: | |
logger.error("Can't run connect_sentry: %s", err, exc_info=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment