Exemplo n.º 1
0
def test_http_request(http_line_factory):
    """Check that the HTTP request is extracted correctly."""
    http_request = 'something in the air'
    line = http_line_factory(http_request=http_request)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('http_request') == http_request
Exemplo n.º 2
0
def test_queues(http_line_factory, server, backend):
    """Check that the server and backend queues are extracted correctly."""
    line = http_line_factory(srv_queue=server, backend_queue=backend)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('srv_queue') == server
    assert matches.group('backend_queue') == backend
Exemplo n.º 3
0
def test_accept_date(http_line_factory):
    """Check that the accept date is extracted correctly."""
    accept_date = datetime.now().strftime('%d/%b/%Y:%H:%M:%S.%f')
    line = http_line_factory(accept_date=accept_date)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('accept_date') == accept_date
Exemplo n.º 4
0
    def test_line_regex_accept_date(self):
        self.accept_date = datetime.now().strftime('%d/%b/%Y:%H:%M:%S.%f')

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertTrue(matches.group('accept_date') in self.accept_date)
Exemplo n.º 5
0
def test_queues(line_factory, server, backend):
    """Check that the server and backend queues are extracted correctly."""
    line = line_factory(queue_server=server, queue_backend=backend)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('queue_server') == server
    assert matches.group('queue_backend') == backend
Exemplo n.º 6
0
    def test_line_regex_accept_date(self):
        self.accept_date = datetime.now().strftime('%d/%b/%Y:%H:%M:%S.%f')

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertTrue(matches.group('accept_date') in self.accept_date)
Exemplo n.º 7
0
    def test_line_regex_http_request(self):
        http_request = 'something in the air'
        self.http_request = http_request

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('http_request'), http_request)
Exemplo n.º 8
0
    def test_line_regex_headers_empty(self):
        self.headers = ''

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('request_headers'), None)
        self.assertEqual(matches.group('response_headers'), None)
Exemplo n.º 9
0
    def test_line_regex_headers_empty(self):
        self.headers = ''

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('request_headers'), None)
        self.assertEqual(matches.group('response_headers'), None)
Exemplo n.º 10
0
    def test_line_regex_http_request(self):
        http_request = 'something in the air'
        self.http_request = http_request

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('http_request'), http_request)
Exemplo n.º 11
0
def test_client_ip_and_port(http_line_factory):
    """Check that the client IP and port are extracted correctly."""
    ip = '192.168.0.250'
    port = '34'
    line = http_line_factory(client_ip=ip, client_port=port)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('client_ip') == ip
    assert matches.group('client_port') == port
Exemplo n.º 12
0
    def test_line_regex_queues(self):
        server = '30'
        backend = '0'
        self.queues = '{0}/{1}'.format(server, backend)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('queue_server'), server)
        self.assertEqual(matches.group('queue_backend'), backend)
Exemplo n.º 13
0
    def test_line_regex_queues(self):
        server = '30'
        backend = '0'
        self.queues = '{0}/{1}'.format(server, backend)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('queue_server'), server)
        self.assertEqual(matches.group('queue_backend'), backend)
Exemplo n.º 14
0
    def test_line_regex_headers(self):
        request = 'something in the air'
        response = 'something not in the air'
        self.headers = '{{{0}}} {{{1}}}'.format(request, response)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertTrue(request in matches.group('request_headers'))
        self.assertTrue(response in matches.group('response_headers'))
Exemplo n.º 15
0
def test_http_request_truncated_regex(http_line_factory):
    """Test that long truncated log lines are properly parsed by the regex"""
    method = 'GET'
    path = '/truncated_pat'
    http_request = f'{method} {path}'
    line = http_line_factory(http_request=http_request)
    # remove trailing double-quote to simulate log line truncation
    matches = HAPROXY_LINE_REGEX.match(line.raw_line[:-1])

    assert matches.group('http_request') == http_request
Exemplo n.º 16
0
    def test_line_regex_client_ip_and_port(self):
        client_ip = '192.168.0.250'
        client_port = '34'
        self.client_ip_and_port = '{0}:{1}'.format(client_ip, client_port)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('client_ip'), client_ip)
        self.assertEqual(matches.group('client_port'), client_port)
Exemplo n.º 17
0
    def test_line_regex_client_ip_and_port(self):
        client_ip = '192.168.0.250'
        client_port = '34'
        self.client_ip_and_port = '{0}:{1}'.format(client_ip, client_port)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('client_ip'), client_ip)
        self.assertEqual(matches.group('client_port'), client_port)
Exemplo n.º 18
0
    def test_line_regex_status_and_bytes_with_sign(self):
        status = '404'
        bytes_read = '+10'
        self.status_and_bytes = '{0} {1}'.format(status, bytes_read)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('status_code'), status)
        self.assertEqual(matches.group('bytes_read'), bytes_read)
Exemplo n.º 19
0
    def test_line_regex_status_and_bytes_for_terminated_request(self):
        status = '-1'
        bytes_read = '0'
        self.status_and_bytes = '{0} {1}'.format(status, bytes_read)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('status_code'), status)
        self.assertEqual(matches.group('bytes_read'), bytes_read)
Exemplo n.º 20
0
    def test_line_regex_status_and_bytes_with_sign(self):
        status = '404'
        bytes_read = '+10'
        self.status_and_bytes = '{0} {1}'.format(status, bytes_read)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('status_code'), status)
        self.assertEqual(matches.group('bytes_read'), bytes_read)
Exemplo n.º 21
0
    def test_line_regex_status_and_bytes_for_terminated_request(self):
        status = '-1'
        bytes_read = '0'
        self.status_and_bytes = '{0} {1}'.format(status, bytes_read)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('status_code'), status)
        self.assertEqual(matches.group('bytes_read'), bytes_read)
Exemplo n.º 22
0
    def test_line_regex_headers(self):
        request = 'something in the air'
        response = 'something not in the air'
        self.headers = '{{{0}}} {{{1}}}'.format(request, response)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertTrue(request in matches.group('request_headers'))
        self.assertTrue(response in matches.group('response_headers'))
Exemplo n.º 23
0
    def test_line_regex_headers_only_one(self):
        request = 'something in the air'
        self.headers = '{{{0}}}'.format(request)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('request_headers'), None)
        self.assertEqual(matches.group('response_headers'), None)
        self.assertTrue(request in matches.group('headers'))
Exemplo n.º 24
0
    def test_line_regex_headers_only_one(self):
        request = 'something in the air'
        self.headers = '{{{0}}}'.format(request)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('request_headers'), None)
        self.assertEqual(matches.group('response_headers'), None)
        self.assertTrue(request in matches.group('headers'))
Exemplo n.º 25
0
def test_tcp_timers(tcp_line_factory, Tw, Tc, Tt):
    """Check that the TCP timers are extracted correctly.

    Note that all timers can be negative but `Ta`,
    and that `tt` is the only one that can have a positive sign.
    """
    line = tcp_line_factory(LineType.TCP, Tw=Tw, Tc=Tc, Tt=Tt)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)
    assert matches.group('tcp_Tw') == Tw
    assert matches.group('tcp_Tc') == Tc
    assert matches.group('tcp_Tt') == Tt
Exemplo n.º 26
0
def test_status_and_bytes(line_factory, status, bytes_read):
    """Check that the status code and bytes are extracted correctly.

    Note that `status` can be negative (for terminated requests),
    and `bytes` can be prefixed with a plus sign.
    """
    line = line_factory(status=status, bytes=bytes_read)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('status_code') == status
    assert matches.group('bytes_read') == bytes_read
Exemplo n.º 27
0
def test_server_names(line_factory):
    """Check that the server names are extracted correctly."""
    frontend_name = 'SomeThing4'
    backend_name = 'Another1'
    server_name = 'Cloud9'
    line = line_factory(frontend_name=frontend_name,
                        backend_name=backend_name,
                        server_name=server_name)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('frontend_name') == frontend_name
    assert matches.group('backend_name') == backend_name
    assert matches.group('server_name') == server_name
Exemplo n.º 28
0
def test_connections_and_retries(line_factory, act, fe, be, srv, retries):
    """Check that the connections and retries are extracted correctly.

    Note that `retries` might have a plus sign prefixed.
    """
    line = line_factory(act=act, fe=fe, be=be, srv=srv, retries=retries)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('act') == act
    assert matches.group('fe') == fe
    assert matches.group('be') == be
    assert matches.group('srv') == srv
    assert matches.group('retries') == retries
Exemplo n.º 29
0
    def test_line_regex_server_names(self):
        frontend_name = 'SomeThing4'
        backend_name = 'Another1'
        server_name = 'Cloud9'
        self.server_names = '{0} {1}/{2}'.format(frontend_name, backend_name,
                                                 server_name)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('frontend_name'), frontend_name)
        self.assertEqual(matches.group('backend_name'), backend_name)
        self.assertEqual(matches.group('server_name'), server_name)
Exemplo n.º 30
0
def test_timers(line_factory, tq, tw, tc, tr, tt):
    """Check that the timers are extracted correctly.

    Note that all timers can be negative but `tt`,
    and that `tt` is the only one that can have a positive sign.
    """
    line = line_factory(tq=tq, tw=tw, tc=tc, tr=tr, tt=tt)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('tq') == tq
    assert matches.group('tw') == tw
    assert matches.group('tc') == tc
    assert matches.group('tr') == tr
    assert matches.group('tt') == tt
Exemplo n.º 31
0
def test_http_timers(http_line_factory, Tq, Tw, Tc, Tr, Ta):
    """Check that the HTTP timers are extracted correctly.

    Note that all timers can be negative but `Ta`,
    and that `tt` is the only one that can have a positive sign.
    """
    line = http_line_factory(LineType.HTTP, Tq=Tq, Tw=Tw, Tc=Tc, Tr=Tr, Ta=Ta)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('http_Tq') == Tq
    assert matches.group('http_Tw') == Tw
    assert matches.group('http_Tc') == Tc
    assert matches.group('http_Tr') == Tr
    assert matches.group('http_Ta') == Ta
Exemplo n.º 32
0
def test_captured_headers(http_line_factory, request_header, response_header):
    """Check that captured headers are extracted correctly."""
    if response_header:
        headers = f' {{{request_header}}} {{{response_header}}}'
    else:
        headers = f' {{{request_header}}}'
    line = http_line_factory(headers=headers)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    if response_header:
        assert matches.group('captured_request_headers') == request_header
        assert matches.group('captured_response_headers') == response_header
    else:
        assert matches.group('headers') == request_header
        assert matches.group('captured_request_headers') is None
        assert matches.group('captured_response_headers') is None
Exemplo n.º 33
0
    def test_line_regex_timers_with_sign(self):
        tq = '-23'
        tw = '-10'
        tc = '-3'
        tr = '-4'
        tt = '+5'
        self.timers = '{0}/{1}/{2}/{3}/{4}'.format(tq, tw, tc, tr, tt)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('tq'), tq)
        self.assertEqual(matches.group('tw'), tw)
        self.assertEqual(matches.group('tc'), tc)
        self.assertEqual(matches.group('tr'), tr)
        self.assertEqual(matches.group('tt'), tt)
Exemplo n.º 34
0
    def test_line_regex_timers_with_sign(self):
        tq = '-23'
        tw = '-10'
        tc = '-3'
        tr = '-4'
        tt = '+5'
        self.timers = '{0}/{1}/{2}/{3}/{4}'.format(tq, tw, tc, tr, tt)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('tq'), tq)
        self.assertEqual(matches.group('tw'), tw)
        self.assertEqual(matches.group('tc'), tc)
        self.assertEqual(matches.group('tr'), tr)
        self.assertEqual(matches.group('tt'), tt)
Exemplo n.º 35
0
    def test_line_regex_server_names(self):
        frontend_name = 'SomeThing4'
        backend_name = 'Another1'
        server_name = 'Cloud9'
        self.server_names = '{0} {1}/{2}'.format(
            frontend_name,
            backend_name,
            server_name,
        )

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('frontend_name'), frontend_name)
        self.assertEqual(matches.group('backend_name'), backend_name)
        self.assertEqual(matches.group('server_name'), server_name)
    def test_line_regex_connections_and_retries_with_sign(self):
        act = '30'
        fe = '0'
        be = '111'
        srv = '412'
        retries = '+314'
        self.connections_and_retries = '{0}/{1}/{2}/{3}/{4}'.format(
            act, fe, be, srv, retries)

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('act'), act)
        self.assertEqual(matches.group('fe'), fe)
        self.assertEqual(matches.group('be'), be)
        self.assertEqual(matches.group('srv'), srv)
        self.assertEqual(matches.group('retries'), retries)
Exemplo n.º 37
0
def test_connections_and_retries(http_line_factory, actconn, feconn, beconn,
                                 srv_conn, retries):
    """Check that the connections and retries are extracted correctly.

    Note that `retries` might have a plus sign prefixed.
    """
    line = http_line_factory(actconn=actconn,
                             feconn=feconn,
                             beconn=beconn,
                             srv_conn=srv_conn,
                             retries=retries)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    assert matches.group('actconn') == actconn
    assert matches.group('feconn') == feconn
    assert matches.group('beconn') == beconn
    assert matches.group('srv_conn') == srv_conn
    assert matches.group('retries') == retries
Exemplo n.º 38
0
    def test_line_regex_connections_and_retries_with_sign(self):
        act = '30'
        fe = '0'
        be = '111'
        srv = '412'
        retries = '+314'
        self.connections_and_retries = '{0}/{1}/{2}/{3}/{4}'.format(
            act, fe, be, srv, retries,
        )

        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('act'), act)
        self.assertEqual(matches.group('fe'), fe)
        self.assertEqual(matches.group('be'), be)
        self.assertEqual(matches.group('srv'), srv)
        self.assertEqual(matches.group('retries'), retries)
Exemplo n.º 39
0
def test_default_values(http_line_factory, default_line_data):
    """Check that the default line with default values is parsed."""
    line = http_line_factory()
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)
    assert matches.group('http_request') == default_line_data['http_request']
Exemplo n.º 40
0
    def test_line_regex_default_values(self):
        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('http_request'), self.http_request)
Exemplo n.º 41
0
def _test_server_names(factory, factory_kwargs):
    line = factory(**factory_kwargs)
    matches = HAPROXY_LINE_REGEX.match(line.raw_line)

    for key, value in factory_kwargs.items():
        assert matches.group(key) == value
Exemplo n.º 42
0
    def test_line_regex_default_values(self):
        log_line = self._build_test_string()
        matches = HAPROXY_LINE_REGEX.match(log_line)

        self.assertEqual(matches.group('http_request'), self.http_request)