示例#1
0
def update_hosts_and_folders(old_site_id: SiteId, new_site_id: SiteId) -> None:
    """Update the Checkmk site attribute in folder and host config files

    - Explicitly configured `site` attributes are updated
    - `site` host_tags entries in the hosts.mk files are updated
    """
    for folder in Folder.all_folders().values():
        # 1. Update explicitly set site in folders
        if folder.attribute("site") == old_site_id:
            logger.debug("Folder %s: Update explicitly set site",
                         folder.alias_path())
            folder.set_attribute("site", new_site_id)

        # 2. Update explicitly set site in hosts
        for host in folder.hosts().values():
            if host.attribute("site") == old_site_id:
                logger.debug("Host %s: Update explicitly set site",
                             host.name())
                host.set_attribute("site", new_site_id)

        # Always rewrite the host config: The host_tags need to be updated, even in case there is no
        # site_id explicitly set. Just to be sure everything is fine we also rewrite the folder
        # config
        logger.debug("Folder %s: Saving config", folder.alias_path())
        folder.save()
        folder.save_hosts()
示例#2
0
def _find_folder_to_scan() -> Optional["CREFolder"]:
    """Find the folder which network scan is longest waiting and return the folder object."""
    folder_to_scan = None
    for folder in Folder.all_folders().values():
        scheduled_time = folder.next_network_scan_at()
        if scheduled_time is not None and scheduled_time < time.time():
            if folder_to_scan is None:
                folder_to_scan = folder
            elif folder_to_scan.next_network_scan_at(
            ) > folder.next_network_scan_at():
                folder_to_scan = folder
    return folder_to_scan