Esempio n. 1
0
def _find_usages_of_contact_group_in_hosts_and_folders(
    name: GroupName, folder: CREFolder
) -> List[Tuple[str, str]]:
    used_in = []
    for subfolder in folder.subfolders():
        used_in += _find_usages_of_contact_group_in_hosts_and_folders(name, subfolder)

    attributes = folder.attributes()
    if name in attributes.get("contactgroups", {}).get("groups", []):
        used_in.append((_("Folder: %s") % folder.alias_path(), folder.edit_url()))

    for host in folder.hosts().values():
        attributes = host.attributes()
        if name in attributes.get("contactgroups", {}).get("groups", []):
            used_in.append((_("Host: %s") % host.name(), host.edit_url()))

    return used_in
Esempio n. 2
0
def _serialize_folder(folder: CREFolder, show_hosts):
    links = []

    if not folder.is_root():
        links.append(
            constructors.link_rel(
                rel="cmk/move",
                href=constructors.object_action_href(
                    "folder_config",
                    folder_slug(folder),
                    action_name="move",
                ),
                method="post",
                title="Move the folder",
            ))

    rv = constructors.domain_object(
        domain_type="folder_config",
        identifier=folder_slug(folder),
        title=folder.title(),
        extensions={
            "path": "/" + folder.path(),
            "attributes": folder.attributes().copy(),
        },
        links=links,
    )
    if show_hosts:
        rv["members"]["hosts"] = constructors.collection_property(
            name="hosts",
            base=constructors.object_href("folder_config",
                                          folder_slug(folder)),
            value=[
                constructors.collection_item(
                    domain_type="host_config",
                    identifier=host.id(),
                    title=host.name(),
                ) for host in folder.hosts().values()
            ],
        )
    return rv