Esempio n. 1
0
async def form_input_tcp_connection_test(req, resp):
    logging.basicConfig(level=logging.DEBUG)
    tcp_endpoint = req.params['tcp-endpoint']
    tcp_port = req.params['tcp-port']
    loop = asyncio.get_running_loop()

    try:
        reader, writer = await asyncio.open_connection(host=tcp_endpoint,
                                                       port=tcp_port)
        connection_info = f'Connection created to {tcp_endpoint} on port {tcp_port}'
        d = data.DinghyData(redis_host,
                            domain_response_code=None,
                            domain_response_time_ms=None,
                            request_url=f'{tcp_endpoint}:{tcp_port}')
        d.save_ping()
        resp.content = api.template('ping_response_tcp_conn.html',
                                    request=tcp_endpoint,
                                    port=tcp_port,
                                    connection_results=connection_info)
    except (asyncio.TimeoutError, ConnectionRefusedError):
        print("Network port not responding")
        connection_info = f'Failed to connect to {tcp_endpoint} on port {tcp_port}'
        resp.status_code = api.status_codes.HTTP_402
        resp.content = api.template('ping_response_tcp_conn.html',
                                    request=tcp_endpoint,
                                    port=tcp_port,
                                    connection_results=connection_info)
Esempio n. 2
0
def _process_request(protocol, domain, params, headers):
    """
    Internal method to run request process, takes protocol and domain for input
    """

    if protocol == "":
        protocol = "https"

    domain_response_code = ""
    domain_response_text = ""
    domain_response_time_ms = ""
    domain_response_headers = {}

    try:
        r = requests.get(
            f'{protocol}://{domain}',
            params=params, timeout=5, headers=headers)
        COMPLETED_REQUEST_COUNTER.inc()
    except requests.exceptions.Timeout as err:
        domain_response_text = f'Timeout: {err}'
        FAILED_REQUEST_COUNTER.inc()
        return (
            domain_response_code, domain_response_text,
            domain_response_time_ms, domain_response_headers
        )
    except requests.exceptions.TooManyRedirects as err:
        domain_response_text = f'TooManyRedirects: {err}'
        FAILED_REQUEST_COUNTER.inc()
        return (
            domain_response_code, domain_response_text,
            domain_response_time_ms, domain_response_headers
        )
    except requests.exceptions.RequestException as err:
        domain_response_text = f'RequestException: {err}'
        FAILED_REQUEST_COUNTER.inc()
        return (
            domain_response_code, domain_response_text,
            domain_response_time_ms, domain_response_headers
        )

    domain_response_code = r.status_code
    domain_response_text = r.text
    domain_response_headers = dict(r.headers)
    domain_response_time_ms = r.elapsed.microseconds / 1000

    d = data.DinghyData(
        redis_host, domain_response_code, domain_response_time_ms, r.url)
    d.save_ping()

    return (
        domain_response_code, domain_response_text,
        domain_response_time_ms, domain_response_headers
    )
Esempio n. 3
0
def _get_all_pinged_urls():
    """Get pinged URLs from Dinghy-ping data module"""
    p = data.DinghyData(redis_host)

    return p.get_all_pinged_urls()