Esempio n. 1
0
def macro_mapping_from_context(
    context: VisualContext,
    single_infos: SingleInfos,
    title: str,
    default_title: str,
    **additional_macros: str,
) -> MacroMapping:
    macro_mapping = {"$DEFAULT_TITLE$": default_title}
    macro_mapping.update({
        macro: str(context[key])
        for macro, key in (
            ("$HOST_NAME$", "host"),
            ("$SERVICE_DESCRIPTION$", "service"),
        ) if key in context and key in single_infos
    })

    if "$HOST_ALIAS$" in title and "$HOST_NAME$" in macro_mapping:
        macro_mapping["$HOST_ALIAS$"] = get_alias_of_host(
            additional_macros.get("$SITE$"),
            macro_mapping["$HOST_NAME$"],
        )

    macro_mapping.update(additional_macros)

    return macro_mapping
Esempio n. 2
0
def title_info_elements(spec_info, title_format) -> Iterable[Tuple[str, str]]:
    if "add_host_name" in title_format:
        host_url = makeuri_contextless(
            request,
            [("view_name", "hoststatus"), ("host", spec_info["host_name"])],
            filename="view.py",
        )
        yield spec_info["host_name"], host_url

    if "add_host_alias" in title_format:
        host_alias = get_alias_of_host(spec_info["site"],
                                       spec_info["host_name"])
        host_url = makeuri_contextless(
            request,
            [("view_name", "hoststatus"), ("host", spec_info["host_name"])],
            filename="view.py",
        )
        yield host_alias, host_url

    if "add_service_description" in title_format:
        service_description = spec_info["service_description"]
        if service_description != "_HOST_":
            service_url = makeuri_contextless(
                request,
                [
                    ("view_name", "service"),
                    ("host", spec_info["host_name"]),
                    ("service", service_description),
                ],
                filename="view.py",
            )
            yield service_description, service_url

    if "add_metric_name" in title_format:
        yield spec_info["metric"], ""
Esempio n. 3
0
def _get_hostname(args, row) -> str:
    args_splitted = args[0].split("/")
    if args_splitted[0] == "$HOSTNAME$":
        return row["host_name"]
    if args_splitted[0] == "$HOSTADDRESS$":
        return row["host_address"]
    if args_splitted[0] == "$HOSTALIAS$":
        return get_alias_of_host(row["site"], row["host_name"])
    return args[0]
Esempio n. 4
0
def macro_mapping_from_context(
    context: VisualContext,
    single_infos: SingleInfos,
    title: str,
) -> MacroMapping:
    macro_mapping = {
        macro: str(context[key])
        for macro, key in (
            ("$HOST_NAME$", "host"),
            ("$SERVICE_DESCRIPTION$", "service"),
        ) if key in context and key in single_infos
    }

    only_sites = visuals.get_only_sites_from_context(context)
    if only_sites and len(only_sites) == 1:
        macro_mapping["$SITE$"] = only_sites[0]

    if "$HOST_ALIAS$" in title and "$HOST_NAME$" in macro_mapping:
        macro_mapping["$HOST_ALIAS$"] = get_alias_of_host(
            macro_mapping.get("$SITE$"),
            macro_mapping["$HOST_NAME$"],
        )

    return macro_mapping