Ejemplo n.º 1
0
def status(*_):
    """Generic ESI status."""

    now = time.time()
    if now - STATUS["timestamp"] > 60:
        code, esi_status = do_request("{}/status.json".format(ESI))
        if code == 200:
            STATUS["status"] = esi_status
        else:
            return ":fire: (failed to fetch status.json)"

    red_routes = [
        route for route in STATUS["status"] if route["status"] == "red"
    ]
    yellow_routes = [
        route for route in STATUS["status"] if route["status"] == "yellow"
    ]

    attachments = []
    if red_routes:
        attachments.append({
            "color":
            "danger",
            "fallback":
            "{} red".format(len(red_routes)),
            "text":
            "{emoji} {count} red {emoji} {details}".format(
                emoji=":fire:" * int(
                    max(
                        round(len(red_routes) / len(STATUS["status"]) * 10),
                        1,
                    )),
                count=len(red_routes),
                details=_status_str(red_routes),
            )
        })
    if yellow_routes:
        attachments.append({
            "color":
            "warning",
            "fallback":
            "{} yellow".format(len(yellow_routes)),
            "text":
            "{emoji} {count} yellow {emoji} {details}".format(
                emoji=":fire_engine:" * int(
                    max(
                        round(len(yellow_routes) / len(STATUS["status"]) * 10),
                        1,
                    )),
                count=len(yellow_routes),
                details=_status_str(yellow_routes),
            )
        })
    if not red_routes and not yellow_routes:
        attachments.append({
            "color": "good",
            "text": "ESI is fully armed and operational!"
        })

    return REPLY(content=None, attachments=attachments)
Ejemplo n.º 2
0
def inconsistency(*_):
    """Return instructions for reporting an inconsistency."""

    return REPLY(content=None, attachments=[
        ISSUE_NEW,
        ISSUE_INCONSISTENCY,
    ])
Ejemplo n.º 3
0
def feature(*_):
    """Return instructions for creating a new feature request."""

    return REPLY(content=None, attachments=[
        ISSUE_NEW,
        ISSUE_FEATURE,
    ])
Ejemplo n.º 4
0
def bug(*_):
    """Return instructions for reporting an ESI bug."""

    return REPLY(content=None, attachments=[
        ISSUE_NEW,
        ISSUE_BUG,
    ])
Ejemplo n.º 5
0
def server_status(datasource):
    """Generate """

    if datasource not in ("tranquility", "singularity"):
        return "Cannot request server status for `{}`".format(datasource)

    status_code, response = do_request("{}/v1/status/?datasource={}".format(
        ESI, datasource))
    server_name = datasource.capitalize()

    if status_code == 200:
        vip = response.get("vip")
        attachment = {
            "color":
            "warning" if vip else "good",
            "title":
            "{} status".format(server_name),
            "fields": [
                {
                    "title": "Players online",
                    "value": "{:,}".format(response["players"]),
                    "short": True,
                },
                {
                    "title": "Server started",
                    "value": response["start_time"],
                    "short": True,
                },
            ],
            "fallback":
            "{} status: {:,} online, started at {}{}".format(
                server_name,
                response["players"],
                response["start_time"],
                ", in VIP" * int(vip is True),
            )
        }
        if vip:
            attachment["fields"].append({"title": "In VIP mode"})

    elif status == 503:
        attachment = {
            "color": "danger",
            "title": "{} status".format(server_name),
            "text": "Offline",
            "fallback": "{} status: Offline".format(server_name),
        }
    else:
        indeterminate = (
            "Cannot determine server status. "
            "It might be offline, or experiencing connectivity issues.")
        attachment = {
            "color": "danger",
            "title": "{} status".format(server_name),
            "text": indeterminate,
            "fallback": "{} status: {}".format(server_name, indeterminate),
        }

    return REPLY(content=None, attachments=[attachment])
Ejemplo n.º 6
0
def status(msg):
    """Return the current ESI health/status."""

    base_url = esi_base_url(msg)

    now = time.time()
    if now - STATUS[base_url]["timestamp"] > 60:
        code, esi_status = do_request("{}/status.json".format(base_url))
        if code == 200:
            STATUS[base_url]["status"] = esi_status
        else:
            return ":fire: (failed to fetch status.json)"

    attachments = []
    categories = [
        ("red", ":fire:", "danger"),
        ("yellow", ":fire_engine:", "warning"),
    ]
    status_json = STATUS[base_url]["status"]

    for status_color, emoji, color_value in categories:
        routes = [
            route for route in status_json if route["status"] == status_color
        ]
        if routes:
            attachments.append({
                "color":
                color_value,
                "fallback":
                "{}: {} out of {}, {:.2%}".format(
                    status_color.capitalize(),
                    len(routes),
                    len(status_json),
                    len(routes) / len(status_json),
                ),
                "text":
                "{emoji} {count} {emoji} {details}".format(
                    emoji=emoji * max(
                        min(int(round(len(routes) / len(status_json) * 10)),
                            5), 1),
                    count="{} {} (out of {}, {:.2%})".format(
                        len(routes),
                        status_color,
                        len(status_json),
                        len(routes) / len(status_json),
                    ),
                    details=_status_str(routes),
                )
            })

    if not attachments:
        attachments.append({
            "color": "good",
            "text": ":ok_hand:",
        })

    return REPLY(content=None, attachments=attachments)
Ejemplo n.º 7
0
def new_issue(*_):
    """Return instructions for opening a new ESI issue."""

    return REPLY(content=None,
                 attachments=[
                     ISSUE_NEW,
                     ISSUE_BUG,
                     ISSUE_FEATURE,
                     ISSUE_INCONSISTENCY,
                 ])
Ejemplo n.º 8
0
def server_status(datsource):
    """Generate a reply describing the status of an EVE server/datasource."""

    if datsource == "tranquility":
        base_url = ESI
    elif datsource == "serenity":
        base_url = ESI_CHINA
    else:
        return "Cannot request server status for `{}`".format(datsource)

    status_code, response = do_request("{}/v1/status/?datasource={}".format(
        base_url,
        datsource,
    ))
    server_name = datsource.capitalize()

    if status_code == 200:
        start_time = datetime.strptime(
            response["start_time"],
            "%Y-%m-%dT%H:%M:%SZ",
        )
        vip = response.get("vip")  # pylint: disable=no-member
        attachment = {
            "color":
            "warning" if vip else "good",
            "title":
            "{} status".format(server_name),
            "fields": [
                {
                    "title": "Players online",
                    "value": "{:,}".format(response["players"]),
                },
                {
                    "title": "Started at",
                    "value": response["start_time"],
                    "short": True,
                },
                {
                    "title": "Running for",
                    "value": _running_for(start_time),
                    "short": True,
                },
            ],
            "fallback":
            "{} status: {:,} online, started at {}{}".format(
                server_name,
                response["players"],
                response["start_time"],
                ", in VIP" * int(vip is True),
            ),
        }
        if vip:
            attachment["fields"].insert(0, {"title": "In VIP mode"})

    elif status_code == 503:
        attachment = {
            "color": "danger",
            "title": "{} status".format(server_name),
            "text": "Offline",
            "fallback": "{} status: Offline".format(server_name),
        }
    else:
        indeterminate = (
            "Cannot determine server status. "
            "It might be offline, or experiencing connectivity issues.")
        attachment = {
            "color": "danger",
            "title": "{} status".format(server_name),
            "text": indeterminate,
            "fallback": "{} status: {}".format(server_name, indeterminate),
        }

    return REPLY(content=None, attachments=[attachment])