本文整理汇总了Python中rollbar.report_message方法的典型用法代码示例。如果您正苦于以下问题:Python rollbar.report_message方法的具体用法?Python rollbar.report_message怎么用?Python rollbar.report_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rollbar
的用法示例。
在下文中一共展示了rollbar.report_message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_sso_key
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def generate_sso_key(self):
request_url = self.get_request_url(resource_path=DSS_321FORMS_API_RESOURCE_SSO_GENERATE)
response = self.request_get(request_url)
exception_reported = False
try:
data = response.json()
sso_key = data.get('SSOKey')
except:
sso_key = None
extra_data = self._get_rollbar_extra_data()
extra_data.update({
'response_text': response.text,
})
rollbar.report_exc_info(extra_data=extra_data)
exception_reported = True
if sso_key is None and not exception_reported:
request = get_current_request()
extra_data = self._get_rollbar_extra_data()
extra_data.update({
'response_text': response.text,
})
rollbar.report_message('Error generating 321Forms SSO key', request=request, extra_data=extra_data)
return sso_key
示例2: get
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def get(self, resource_type, params=None, headers=None):
"""Performs an Iterable API GET request
"""
url = self.get_resource_url(resource_type)
if params is None:
params = {}
params.update({
'apiKey' : self.api_key,
})
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
pass
else:
extra_data = {
'response' : response.json(),
}
rollbar.report_message('Unexpected response from Iterable API GET request', level='info', extra_data=extra_data)
return response
示例3: post
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def post(self, resource_type, payload=None, params=None, headers=None):
"""Performs an Iterable API POST request
"""
url = self.get_resource_url(resource_type)
if params is None:
params = {}
params.update({
'apiKey' : self.api_key,
})
response = requests.post(url, params=params, headers=headers, json=payload)
if response.status_code == 200:
pass
else:
extra_data = {
'response' : response.json(),
}
rollbar.report_message('Unexpected response from Iterable API POST request', level='info', extra_data=extra_data)
return response
示例4: delete
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def delete(self, resource_type, resource_params=None, params=None, headers=None):
"""Performs an Iterable API POST request
"""
url = self.get_resource_url(resource_type)
if resource_params:
url = url % resource_params
if params is None:
params = {}
params.update({
'apiKey' : self.api_key,
})
response = requests.delete(url, params=params, headers=headers)
if response.status_code == 200:
pass
else:
extra_data = {
'response' : response.json()
}
rollbar.report_message('Unexpected response from Iterable API DELETE request', extra_data=extra_data)
return response
##
# events
示例5: failed_recaptcha_on_login
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def failed_recaptcha_on_login(user, request=None):
extra_data = {
'user' : {
'id': user.id,
'username': user.username,
'email': user.email,
},
}
message = 'Failed reCAPTCHA. Suspicious login detected.'
rollbar.report_message(
message,
request=request,
extra_data=extra_data
)
if htk_setting('HTK_SLACK_NOTIFICATIONS_ENABLED'):
slack_message = '%s User: %s <%s>' % (
message,
user.username,
user.email,
)
slack_notify(slack_message, level='warning')
示例6: resolve_instances
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def resolve_instances(instance, path):
if not path:
yield instance
return
attr = path[0]
path = path[1:]
try:
value = getattr(instance, attr)
except ObjectDoesNotExist:
value = None
if value is None:
return
if isinstance(value, models.Model):
for x in resolve_instances(value, path):
yield x
elif hasattr(value, 'all'):
for singular in value.all():
for x in resolve_instances(singular, path):
yield x
else:
rollbar.report_message(
'Unknown value in resolve_instance({}, {}): {}'.format(instance, path, value),
level='error'
)
示例7: invalidate_for_instance
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def invalidate_for_instance(instance, mps, save=False):
"""Invalidates the Materialized Properties `mps` for this `instance
Save immediately if `save == True`
"""
if isinstance(mps, basestring):
mps = [mps]
for mp in mps:
if isinstance(mp, basestring):
model = instance._meta.model
if model._meta.proxy:
model = model._meta.proxy_for_model
mp = registered_mps[model][mp]
value = mp.get_real(instance)
# rollbar.report_message(
# 'setattr (invalidation) attr=%s, value=%s, instance=%s' % (
# mp.field_name,
# value,
# fmt(instance),
# ),
# level='info'
# )
mp.update_on_instance(instance, value, save=save)
示例8: default
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def default(self, request, exception):
rollbar.report_message(str(exception))
return super().default(request, exception)
示例9: add_monitoring
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def add_monitoring():
rollbar.init(os.environ.get('ROLLBAR_SECRET'))
## delete the next line if you dont want this event anymore
rollbar.report_message('Rollbar is configured correctly')
got_request_exception.connect(rollbar.contrib.flask.report_exception, app)
示例10: emit
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def emit(self, record):
level = record.levelname.lower()
if level not in self.SUPPORTED_LEVELS:
return
if record.levelno < self.notify_level:
return
try:
data = json.loads(record.msg)
except json.JSONDecodeError:
return super(StructlogRollbarHandler, self).emit(record)
# Title and grouping
data['title'] = data['fingerprint'] = self.format_title(data)
uuid = rollbar.report_message(
message=data.pop('traceback', data['title']),
level=level,
request=rollbar.get_request(),
extra_data={},
payload_data=data,
)
if uuid:
record.rollbar_uuid = uuid
示例11: deprecated
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def deprecated(func):
"""Decorator for reporting deprecated function calls
Use this decorator sparingly, because we'll be charged if we make too many Rollbar notifications
"""
@wraps(func)
def wrapped(*args, **kwargs):
# try to get a request, may not always succeed
request = get_current_request()
# notify a maximum of once per function per request/session
if request:
if DEPRECATED_ROLLBAR_NOTIFIED not in request.session:
deprecated_notifications = {}
request.session[DEPRECATED_ROLLBAR_NOTIFIED] = deprecated_notifications
deprecated_notifications = request.session[DEPRECATED_ROLLBAR_NOTIFIED]
key = '%s' % func
# first get it
already_notified = deprecated_notifications.get(key, False)
# then mark it
deprecated_notifications[key] = True
else:
already_notified = False
if not already_notified:
rollbar.report_message('Deprecated function call warning: %s' % func, 'warning', request)
return func(*args, **kwargs)
return wrapped
示例12: debugger
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def debugger(request):
import rollbar
message = request.GET.get('m')
rollbar.report_message(message, 'debug')
from htk.api.utils import json_response_okay
response = json_response_okay()
return response
示例13: process_request
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def process_request(self, request):
"""Replace the authenticated `request.user` if properly emulating
"""
if (
request.path.startswith(htk_setting('HTK_PATH_ADMIN'))
or request.path.startswith(htk_setting('HTK_PATH_ADMINTOOLS'))
):
# disallow emulation for /admin and /admintools
pass
elif is_allowed_to_emulate_users(request.user):
from htk.apps.accounts.utils import get_user_by_id
from htk.apps.accounts.utils import get_user_by_username
user_id = request.COOKIES.get('emulate_user_id')
username = request.COOKIES.get('emulate_user_username')
is_attempting_to_emulate = user_id or username
if is_attempting_to_emulate:
if user_id:
targeted_user = get_user_by_id(user_id)
elif username:
targeted_user = get_user_by_username(username)
else:
rollbar.report_message('Impossible case: attempting to emulate another user but not specified')
if targeted_user is None:
messages.error(request, 'Cannot Emulate: User does not exist', fail_silently=True)
else:
if is_allowed_to_emulate(request.user, targeted_user):
request.original_user = request.user
request.user = targeted_user
else:
messages.error(request, 'Cannot Emulate: Not allowed to emulate that user', fail_silently=True)
else:
# not attempting to emulate
pass
else:
# is not allowed or is not attempting to emulate users
pass
示例14: convert_weather_icon_to_emoji
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def convert_weather_icon_to_emoji(weather_icon):
"""
https://darksky.net/dev/docs/response
http://www.webpagefx.com/tools/emoji-cheat-sheet/
"""
icons = {
'default' : ':sunny:',
'clear-day' : ':sun_small_cloud:',
'clear-night' : ':night_with_stars:',
'rain' : ':rain_cloud:',
'snow' : ':snow_cloud:',
'sleet' : ':snow_cloud:', # TODO better icon
'wind' : ':wind_chime:',
'fog' : ':fog:',
'cloudy' : ':cloud:',
'partly-cloudy-day' : ':partly_sunny:',
'partly-cloudy-night' : ':night_with_stars:', # TODO better icon
'hail' : ':snow_cloud:', # TODO better icon
'thunderstorm' : ':thunder_cloud_and_rain:',
'tornado' : ':tornado:',
}
if weather_icon not in icons:
weather_icon = 'default'
rollbar.report_message('Unmatched weather icon: %s' % weather_icon)
icon = icons.get(weather_icon)
return icon
示例15: get
# 需要导入模块: import rollbar [as 别名]
# 或者: from rollbar import report_message [as 别名]
def get(self, resource_type, resource_args=None, params=None, headers=None, auth_type='bearer', refresh_token=True):
"""Performs a Fitbit API GET request
`auth_type` the string 'basic' or 'bearer'
`refresh_token` if True, will refresh the OAuth token when needed
"""
url = self.get_resource_url(resource_type, resource_args=resource_args)
if headers is None:
headers = self.make_headers(auth_type, headers=headers)
response = requests.get(url, headers=headers, params=params)
if response.status_code == 401:
# TODO: deprecate. should proactively refresh
if refresh_token:
was_refreshed = self.refresh_oauth2_token()
if was_refreshed:
# if token was successfully refreshed, repeat request
response = self.get(resource_type, resource_args=resource_args, params=params, headers=headers, auth_type=auth_type, refresh_token=False)
else:
pass
else:
extra_data = {
'user_id' : self.social_auth_user.user.id,
'username' : self.social_auth_user.user.username,
'response' : response.json(),
}
rollbar.report_message('Fitbit OAuth token expired, needs refreshing', extra_data=extra_data)
elif response.status_code == 200:
pass
else:
extra_data = {
'response' : response.json(),
}
rollbar.report_message('Unexpected response from Fitbit API GET request', extra_data=extra_data)
return response