def dump_structure(wato_folder: hosts_and_folders.CREFolder, indent=0): indent_space = " " * indent * 6 sys.stdout.write( f"{indent_space + '->' + str(wato_folder):80} {wato_folder.path()}\n" ) sys.stdout.write("\n".join( f"{indent_space} {x}" for x in pprint.pformat(wato_folder.attributes()).split("\n")) + "\n") for subfolder in wato_folder.subfolders(): dump_structure(subfolder, indent + 1)
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
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
def etag_of_folder(folder: CREFolder) -> ETags: return constructors.etag_of_dict({ "path": folder.path(), "attributes": folder.attributes(), "hosts": folder.host_names(), })