示例#1
0
def init_sentry():
    logger.debug('Initializing Sentry loghandler')
    client = LambdaClient(auto_log_stacks=True)
    loghandler = SentryHandler(client)
    loghandler.setLevel('ERROR')
    setup_logging(loghandler)

    logger.debug('Applying Sentry celery signals and logging hooks')
    register_logger_signal(client, loglevel=logging.INFO)
    register_signal(client, ignore_expected=False)
    return client
示例#2
0
import aiohttp
import ciso8601
import kinto_http
from decouple import config
from raven.contrib.awslambda import LambdaClient

from buildhub import utils
from buildhub.inventory_to_records import (__version__, NB_RETRY_REQUEST,
                                           fetch_json, fetch_listing,
                                           fetch_metadata, scan_candidates)
from buildhub.configure_markus import get_metrics

# Optional Sentry with synchronuous client.
SENTRY_DSN = config('SENTRY_DSN', default=None)
sentry = LambdaClient(
    SENTRY_DSN,
    release=__version__,
)

logger = logging.getLogger()  # root logger.
metrics = get_metrics('buildhub')


async def main(loop, event):
    """
    Trigger when S3 event kicks in.
    http://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html
    """
    server_url = config('SERVER_URL', default='http://localhost:8888/v1')
    bucket = config('BUCKET', default='build-hub')
    collection = config('COLLECTION', default='releases')
    kinto_auth = tuple(config('AUTH', 'user:pass').split(':'))
示例#3
0
import json
import os
import time
import boto3
import logging

import sys, os  # noqa
# get this file's directory independent of where it's run from
here = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(here, "vendored"))

import requests  # noqa
from raven.contrib.awslambda import LambdaClient  # noqa

raven_client = LambdaClient()

logger = logging.getLogger()
logger.setLevel(logging.INFO)

boto_client = None


def current_time_in_seconds():
    return time.time()


def response_with_message(message):
    logger.info(message)
    return {"statusCode": 200, "body": json.dumps({"message": message})}

示例#4
0
import logging

from raven.contrib.awslambda import LambdaClient

from kleroteria import settings, subscription  # noqa: E402

# https://gist.github.com/niranjv/fb95e716151642e8ca553b0e38dd152e#gistcomment-2302572
FORMAT = '%(levelname)s: %(asctime)s - %(name)s (%(module)s:%(lineno)s): %(message)s'
logger = logging.getLogger()
for h in logger.handlers:
    h.setFormatter(logging.Formatter(FORMAT))
logger.setLevel(logging.WARNING)

logger = logging.getLogger('kleroteria.list_ingest')

raven_client = LambdaClient(include_paths=['kleroteria', 'task'], )


@raven_client.capture_exceptions
def handler(event, context):
    queue = settings.botos.resource('sqs').Queue(settings.list_queue_url)
    results = []

    start_time = datetime.datetime.now()
    while (datetime.datetime.now() -
           start_time).total_seconds() < settings.ingest_soft_timeout_secs:
        logger.info('receiving messages')
        messages = queue.receive_messages(
            MaxNumberOfMessages=10,
            WaitTimeSeconds=settings.queue_wait_secs,
            AttributeNames=['All'],
示例#5
0
import sys
import os
import asyncio

sys.path.append(os.path.join(os.getcwd(), 'dependencies'))

import boto3
import urllib3
from bypass import ByPass
from raven.contrib.awslambda import LambdaClient

urllib3.disable_warnings()
client = LambdaClient(os.environ['SENTRY_AUTH_URL'])


@client.capture_exceptions
def handler(event, context):
    session = boto3.Session(
        aws_access_key_id=os.environ['ROBOT_AWS_ACCESS_KEY_ID'],
        aws_secret_access_key=os.environ['ROBOT_AWS_SECRET_ACCESS_KEY'],
    )

    async def main():
        bypass = ByPass(session)
        page = await bypass.setUp()

        await page.goto('https://www.google.com/recaptcha/api2/demo')
        await bypass.run()
        await bypass.print_and_screenshot()

    asyncio.get_event_loop().run_until_complete(main())