fixing an issue where sentry logger would fail to get tags from grains and some other lint fixes for this file

This commit is contained in:
Wesley Whetstone 2018-09-26 10:30:56 -07:00
parent 413868329c
commit 201697d55c
No known key found for this signature in database
GPG key ID: 327AC40B0253A798

View file

@ -112,13 +112,16 @@ __virtualname__ = 'sentry'
def __virtual__():
if HAS_RAVEN is True:
__grains__ = salt.loader.grains(__opts__)
__salt__ = salt.loader.minion_mods(__opts__)
return __virtualname__
return False
def setup_handlers():
'''
sets up the sentry handler
'''
__grains__ = salt.loader.grains(__opts__)
__salt__ = salt.loader.minion_mods(__opts__)
if 'sentry_handler' not in __opts__:
log.debug('No \'sentry_handler\' key was found in the configuration')
return False
@ -132,7 +135,9 @@ def setup_handlers():
transport_registry = TransportRegistry(default_transports)
url = urlparse(dsn)
if not transport_registry.supported_scheme(url.scheme):
raise ValueError('Unsupported Sentry DSN scheme: {0}'.format(url.scheme))
raise ValueError(
'Unsupported Sentry DSN scheme: %s', url.scheme
)
except ValueError as exc:
log.info(
'Raven failed to parse the configuration provided DSN: %s', exc
@ -201,7 +206,11 @@ def setup_handlers():
context_dict = {}
if context is not None:
for tag in context:
tag_value = __salt__['grains.get'](tag)
try:
tag_value = __grains__[tag]
except KeyError:
log.debug('Sentry tag \'%s\' not found in grains.', tag)
continue
if len(tag_value) > 0:
context_dict[tag] = tag_value
if len(context_dict) > 0:
@ -215,4 +224,7 @@ def setup_handlers():
def get_config_value(name, default=None):
'''
returns a configuration option for the sentry_handler
'''
return __opts__['sentry_handler'].get(name, default)