コード例 #1
0
ファイル: marathon_serviceinit.py プロジェクト: sbcoba/paasta
def format_haproxy_backend_row(backend, is_correct_instance):
    """Pretty Prints the status of a given haproxy backend
    Takes the fields described in the CSV format of haproxy:
    http://www.haproxy.org/download/1.5/doc/configuration.txt
    And tries to make a good guess about how to represent them in text
    """
    backend_name = backend['svname']
    backend_hostname = backend_name.split("_")[-1]
    backend_port = backend_name.split("_")[0].split(":")[-1]
    pretty_backend_name = "%s:%s" % (backend_hostname, backend_port)
    if backend['status'] == "UP":
        status = PaastaColors.default(backend['status'])
    elif backend['status'] == 'DOWN' or backend['status'] == 'MAINT':
        status = PaastaColors.red(backend['status'])
    else:
        status = PaastaColors.yellow(backend['status'])
    lastcheck = "%s/%s in %sms" % (backend['check_status'],
                                   backend['check_code'],
                                   backend['check_duration'])
    lastchange = humanize.naturaltime(
        datetime.timedelta(seconds=int(backend['lastchg'])))

    row = (
        '      %s' % pretty_backend_name,
        lastcheck,
        lastchange,
        status,
    )

    if is_correct_instance:
        return row
    else:
        return tuple(
            PaastaColors.grey(remove_ansi_escape_sequences(col))
            for col in row)
コード例 #2
0
def format_haproxy_backend_row(backend, is_correct_instance):
    """Pretty Prints the status of a given haproxy backend
    Takes the fields described in the CSV format of haproxy:
    http://www.haproxy.org/download/1.5/doc/configuration.txt
    And tries to make a good guess about how to represent them in text
    """
    backend_name = backend["svname"]
    backend_hostname = backend_name.split("_")[-1]
    backend_port = backend_name.split("_")[0].split(":")[-1]
    pretty_backend_name = f"{backend_hostname}:{backend_port}"
    if backend["status"] == "UP":
        status = PaastaColors.default(backend["status"])
    elif backend["status"] == "DOWN" or backend["status"] == "MAINT":
        status = PaastaColors.red(backend["status"])
    else:
        status = PaastaColors.yellow(backend["status"])
    lastcheck = "{}/{} in {}ms".format(
        backend["check_status"], backend["check_code"], backend["check_duration"]
    )
    lastchange = humanize.naturaltime(
        datetime.timedelta(seconds=int(backend["lastchg"]))
    )

    row = ("      %s" % pretty_backend_name, lastcheck, lastchange, status)

    if is_correct_instance:
        return row
    else:
        return tuple(
            PaastaColors.grey(remove_ansi_escape_sequences(col)) for col in row
        )
コード例 #3
0
def format_haproxy_backend_row(backend, is_correct_instance):
    """Pretty Prints the status of a given haproxy backend
    Takes the fields described in the CSV format of haproxy:
    http://www.haproxy.org/download/1.5/doc/configuration.txt
    And tries to make a good guess about how to represent them in text
    """
    backend_name = backend['svname']
    backend_hostname = backend_name.split("_")[-1]
    backend_port = backend_name.split("_")[0].split(":")[-1]
    pretty_backend_name = "%s:%s" % (backend_hostname, backend_port)
    if backend['status'] == "UP":
        status = PaastaColors.default(backend['status'])
    elif backend['status'] == 'DOWN' or backend['status'] == 'MAINT':
        status = PaastaColors.red(backend['status'])
    else:
        status = PaastaColors.yellow(backend['status'])
    lastcheck = "%s/%s in %sms" % (backend['check_status'], backend['check_code'], backend['check_duration'])
    lastchange = humanize.naturaltime(datetime.timedelta(seconds=int(backend['lastchg'])))

    row = (
        '      %s' % pretty_backend_name,
        lastcheck,
        lastchange,
        status,
    )

    if is_correct_instance:
        return row
    else:
        return tuple(PaastaColors.grey(remove_ansi_escape_sequences(col)) for col in row)
コード例 #4
0
ファイル: status.py プロジェクト: cb-salaikumar/paasta
def build_smartstack_backends_table(backends):
    rows = [("Name", "LastCheck", "LastChange", "Status")]
    for backend in backends:
        if backend.status == "UP":
            status = PaastaColors.default(backend.status)
        elif backend.status == "DOWN":
            status = PaastaColors.red(backend.status)
        elif backend.status == "MAINT":
            status = PaastaColors.grey(backend.status)
        else:
            status = PaastaColors.yellow(backend.status)

        if backend.check_duration is None:
            check_duration = ""
        else:
            check_duration = str(backend.check_duration)

        row = (
            f"{backend.hostname}:{backend.port}",
            f"{backend.check_status}/{backend.check_code} in {check_duration}ms",
            humanize.naturaltime(timedelta(seconds=backend.last_change)),
            status,
        )

        if not backend.has_associated_task:
            row = tuple(
                PaastaColors.grey(remove_ansi_escape_sequences(col)) for col in row
            )

        rows.append(row)

    return format_table(rows)
コード例 #5
0
def test_format_haproxy_backend_row():
    actual = marathon_serviceinit.format_haproxy_backend_row(
        backend={
            "svname": "169.254.123.1:1234_host1",
            "status": "UP",
            "check_status": "L7OK",
            "check_code": "200",
            "check_duration": 4,
            "lastchg": 0,
        },
        is_correct_instance=True,
    )
    expected = ("      host1:1234", "L7OK/200 in 4ms", "now", PaastaColors.default("UP"))
    assert actual == expected
コード例 #6
0
def test_format_haproxy_backend_row():
    actual = marathon_serviceinit.format_haproxy_backend_row(
        backend={
            'svname': '169.254.123.1:1234_host1',
            'status': 'UP',
            'check_status': 'L7OK',
            'check_code': '200',
            'check_duration': 4,
            'lastchg': 0
        },
        is_correct_instance=True,
    )
    expected = (
        '      host1:1234',
        'L7OK/200 in 4ms',
        'now',
        PaastaColors.default('UP'),
    )
    assert actual == expected
コード例 #7
0
def test_format_haproxy_backend_row():
    actual = marathon_serviceinit.format_haproxy_backend_row(
        backend={
            'svname': '169.254.123.1:1234_host1',
            'status': 'UP',
            'check_status': 'L7OK',
            'check_code': '200',
            'check_duration': 4,
            'lastchg': 0
        },
        is_correct_instance=True,
    )
    expected = (
        '      host1:1234',
        'L7OK/200 in 4ms',
        'now',
        PaastaColors.default('UP'),
    )
    assert actual == expected
コード例 #8
0
def test_format_haproxy_backend_row():
    actual = marathon_serviceinit.format_haproxy_backend_row(
        backend={
            "svname": "169.254.123.1:1234_host1",
            "status": "UP",
            "check_status": "L7OK",
            "check_code": "200",
            "check_duration": 4,
            "lastchg": 0,
        },
        is_correct_instance=True,
    )
    expected = (
        "      host1:1234",
        "L7OK/200 in 4ms",
        "now",
        PaastaColors.default("UP"),
    )
    assert actual == expected