Exemplo n.º 1
0
 def __init__(self,):
     super(LogApiTokenExpired, self).__init__()
     if self.stats:
         tags = ['version:'+str(Config.API_VERSION_MINOR), 'application:rest-api']
         ip = get_remote_addr()
         self.stats.track(get_remote_addr(),
                          'api_auth_token_expired',
                          properties=dict(tags=tags,
                                          ip=ip,
                                          ignore_time=True,
                                          ))
Exemplo n.º 2
0
    def __init__(self,
                 value):
        super(LogApiCallWeight, self).__init__()
        if self.stats:
            tags = ['version:'+str(Config.API_VERSION_MINOR), 'application:rest-api']
            ip = get_remote_addr()

            self.stats.track(get_remote_addr(),
                             'api_call_weight',
                             properties=dict(value=value,
                                             tags=tags,
                                             ip=ip,
                                             ignore_time = True,
                                             ))
Exemplo n.º 3
0
 def __init__(self, rate_limiter):
     super(LogApiCallCount, self).__init__()
     if self.stats:
         tags = ['version:'+str(Config.API_VERSION_MINOR),
                 'application:rest-api',
                 'api-key:'+rate_limiter._auth_key.id,
                 'method:'+request.environ['REQUEST_METHOD'],
                 'endpoint:'+request.url_rule.rule.split('<')[0].split(request.blueprint)[1]]
         ip = get_remote_addr()
         self.stats.track(get_remote_addr(),
                          'api_call_count',
                          properties=dict(tags=tags,
                                          ip=ip,
                                          ignore_time = True,
                                          ))
Exemplo n.º 4
0
    def __init__(self, exception):

        super(LogException, self).__init__()
        if self.stats:
            title = "Exception in REST API"
            import traceback
            try:
                raise exception
            except:
                tb = traceback.format_exc(limit=3)
                #TODO: the traceback reporting is not working as expexted. might need to be called from a subclassed Flask app, and not from a signal
                #http://flask.pocoo.org/snippets/127/

            plain_exception = '%s: %s' % (exception.__class__.__name__,
                                          str(exception))
            text = json.dumps(
                dict(  #traceback= tb,
                    url=str(request.url),
                    method=str(request.method),
                    args=request.args,
                    headers=request.headers.items(),
                    exception_class=exception.__class__.__name__,
                    exception=plain_exception,
                ))
            tags = [
                'version:' + str(Config.API_VERSION_MINOR),
                'application:rest-api', exception.__class__.__name__
            ]

            alert_type = 'error'
            if isinstance(exception, HTTPException):
                if str(exception.code)[0] == '4':
                    alert_type = 'warning'
                    title = '4XX error in REST API'

            ip = get_remote_addr()
            self.stats.track(ip,
                             'api_error',
                             properties=dict(
                                 title=title,
                                 text=text,
                                 tags=tags,
                                 alert_type=alert_type,
                                 ip=ip,
                                 ignore_time=True,
                             ))
Exemplo n.º 5
0
    def __init__(self,
                 message):
        super(LogApiTokenInvalidDomain, self).__init__()
        if self.stats:
            message['host']= request.environ.get('HTTP_HOST').split(':')[0]

            title = "Invalid token used"
            text = json.dumps(message)
            tags = ['version:'+str(Config.API_VERSION_MINOR), 'application:rest-api']
            ip = get_remote_addr()
            self.stats.track(ip,
                             'api_auth_token_invalid_domain',
                             properties=dict(title=title,
                                             text=text,
                                             tags=tags,
                                             alert_type='error',
                                             ip=ip,
                                             ignore_time=True,
                                             ))
Exemplo n.º 6
0
    def __init__(self,
                 rate_limiter):

        super(RateLimitExceeded, self).__init__()
        if self.stats:
            title = "Api limit exceeded"
            text = json.dumps(rate_limiter.__dict__)
            tags = ['version:'+str(Config.API_VERSION_MINOR),
                    'application:rest-api',
                    'api-key:'+rate_limiter._auth_key.id]
            ip = get_remote_addr()

            self.stats.track(rate_limiter._auth_key.id,
                             'api_limit_exceeded',
                             properties=dict(title=title,
                                             text=text,
                                             tags=tags,
                                             alert_type='error',
                                             ip=ip,
                                             ignore_time = True,))
Exemplo n.º 7
0
 def get_remote_addr():
     return get_remote_addr()