Exemplo n.º 1
0
def handler_nested(requester: Requester, uris: Sequence[str],
                   identifier: str) -> AnyGenerator:
    # Get all appliance UUIDs
    members = requester.get(uris[0])
    yield members

    # Get appliance's dashboard per UUID
    for member in members["members"]:
        yield requester.get("%s/%s" % (uris[1], member[identifier]))
Exemplo n.º 2
0
def output_cluster(requester: Requester) -> None:
    LOGGING.debug("do request..")
    obj = requester.get("cluster")
    LOGGING.debug("got %d keys", len(obj.keys()))

    write_title("info")
    writer = gen_csv_writer()
    writer.writerow(["name", "version"])
    writer.writerow([obj['name'], obj['version']])
Exemplo n.º 3
0
def output_containers(requester: Requester) -> None:
    LOGGING.debug("do request..")
    obj = requester.get("containers")
    LOGGING.debug("got %d containers", len(obj["entities"]))

    write_title("containers")
    writer = gen_csv_writer()
    writer.writerow(["name", "usage", "capacity"])
    for entity in obj['entities']:
        writer.writerow([
            entity['name'], entity['usageStats']['storage.user_usage_bytes'],
            entity['usageStats']['storage.user_capacity_bytes']
        ])
Exemplo n.º 4
0
def output_storage_pools(requester: Requester) -> None:
    LOGGING.debug("do request..")
    obj = requester.get("storage_pools")
    LOGGING.debug("got %d entities", len(obj["entities"]))

    write_title("storage_pools")
    writer = gen_csv_writer()
    writer.writerow(["name", "usage", "capacity"])

    for entity in obj["entities"]:
        writer.writerow([
            entity["name"],
            entity["usageStats"]["storage.usage_bytes"],
            entity["usageStats"]["storage.capacity_bytes"],
        ])
Exemplo n.º 5
0
def output_alerts(requester: Requester) -> Generator[SectionLine, None, None]:
    needed_context_keys = {"vm_type"}

    LOGGING.debug("do request..")
    obj = requester.get(
        "alerts",
        parameters={
            "resolved": "false",
            "acknowledged": "false"
        },
    )
    LOGGING.debug("got %d alerts", len(obj["entities"]))

    yield ("timestamp", "severity", "message", "context")

    for entity in obj["entities"]:
        # The message is stored as a pattern with placeholders, the
        # actual values are stored in context_values, the keys in
        # context_types
        full_context = dict(
            zip(entity["contextTypes"], entity["contextValues"]))

        # create a thinned out context we can provide together with the alert data in order to
        # provide more sophisticated checks in the future (this could be made a cli option, too)
        thin_context = {
            k: v
            for k, v in full_context.items() if k in needed_context_keys
        }

        # We have seen informational messages in format:
        # {dev_type} drive {dev_name} on host {ip_address} has the following problems: {err_msg}
        # In this case the keys have no values so we can not assign it to the message
        # To handle this, we output a message without assigning the keys
        try:
            message = entity["message"].format(**full_context)
        except KeyError:
            message = entity["message"]

        # message can contain line breaks which confuses the parser.
        message = message.replace("\n", r"\n")
        yield (entity["createdTimeStampInUsecs"], entity["severity"], message,
               thin_context)
Exemplo n.º 6
0
def handler_simple(requester: Requester, uris: Sequence[str]) -> AnyGenerator:
    yield from (requester.get(uri) for uri in uris)