def _get_hosts_to_discover(self): # type: () -> List[DiscoveryHost] if self._only_failed_invcheck: restrict_to_hosts = self._find_hosts_with_failed_discovery_check() else: restrict_to_hosts = None if self._only_ok_agent: skip_hosts = self._find_hosts_with_failed_agent() else: skip_hosts = [] # 'all' not set -> only inventorize checked hosts hosts_to_discover = [] if not self._all: filterfunc = None if self._only_failed: filterfunc = lambda host: host.discovery_failed() for host_name in get_hostnames_from_checkboxes(filterfunc): if restrict_to_hosts and host_name not in restrict_to_hosts: continue if host_name in skip_hosts: continue host = Folder.current().host(host_name) host.need_permission("write") hosts_to_discover.append( DiscoveryHost(host.site_id(), host.folder().path(), host_name)) else: # all host in this folder, maybe recursively. New: we always group # a bunch of subsequent hosts of the same folder into one item. # That saves automation calls and speeds up mass inventories. entries = self._recurse_hosts(Folder.current()) for host_name, folder in entries: if restrict_to_hosts is not None and host_name not in restrict_to_hosts: continue if host_name in skip_hosts: continue host = folder.host(host_name) host.need_permission("write") hosts_to_discover.append( DiscoveryHost(host.site_id(), host.folder().path(), host_name)) return hosts_to_discover
def _get_hosts_from_request(self, request: Dict) -> List[DiscoveryHost]: if not request["hostnames"]: raise MKUserError(None, _("You have to specify some hosts")) hosts_to_discover = [] for host_name in request["hostnames"]: host = Host.host(host_name) if host is None: raise MKUserError(None, _("The host '%s' does not exist") % host_name) host.need_permission("write") hosts_to_discover.append(DiscoveryHost(host.site_id(), host.folder().path(), host_name)) return hosts_to_discover