Пример #1
0
def _preprocess_hostnames(
    arg_host_names: Set[HostName],
    config_cache: config.ConfigCache,
    only_host_labels: bool,
) -> Set[HostName]:
    """Default to all hosts and expand cluster names to their nodes"""
    if not arg_host_names:
        console.verbose("Discovering %shost labels on all hosts\n" %
                        ("services and " if not only_host_labels else ""))
        arg_host_names = config_cache.all_active_realhosts()
    else:
        console.verbose("Discovering %shost labels on: %s\n" %
                        ("services and " if not only_host_labels else "",
                         ", ".join(sorted(arg_host_names))))

    host_names: Set[HostName] = set()
    # For clusters add their nodes to the list. Clusters itself
    # cannot be discovered but the user is allowed to specify
    # them and we do discovery on the nodes instead.
    for host_name, host_config in [(hn, config_cache.get_host_config(hn))
                                   for hn in arg_host_names]:
        if not host_config.is_cluster:
            host_names.add(host_name)
            continue

        if host_config.nodes is None:
            raise MKGeneralException("Invalid cluster configuration")
        host_names.update(host_config.nodes)

    return host_names
Пример #2
0
def _ip_to_hostname(config_cache: config.ConfigCache,
                    ip: Optional[HostAddress]) -> Optional[HostName]:
    if not _config_cache.exists("ip_to_hostname"):
        cache = _config_cache.get_dict("ip_to_hostname")

        for host in config_cache.all_active_realhosts():
            try:
                cache[ip_lookup.lookup_ipv4_address(host)] = host
            except Exception:
                pass
    else:
        cache = _config_cache.get_dict("ip_to_hostname")

    return cache.get(ip)
Пример #3
0
def get_cluster_nodes_for_config(config_cache: ConfigCache,
                                 host_config: HostConfig) -> List[HostName]:

    if host_config.nodes is None:
        return []

    nodes = host_config.nodes[:]
    _verify_cluster_address_family(nodes, config_cache, host_config)
    _verify_cluster_datasource(nodes, config_cache, host_config)
    for node in nodes:
        if node not in config_cache.all_active_realhosts():
            warning("Node '%s' of cluster '%s' is not a monitored host in this site." %
                    (node, host_config.hostname))
            nodes.remove(node)
    return nodes
Пример #4
0
def _ip_to_hostname(config_cache: config.ConfigCache,
                    ip: Optional[HostAddress]) -> Optional[HostName]:
    if "ip_to_hostname" not in _config_cache:
        cache = _config_cache.get("ip_to_hostname")

        for host in config_cache.all_active_realhosts():
            host_config = config_cache.get_host_config(host)
            try:
                cache[config.lookup_ip_address(host_config, family=socket.AF_INET)] = host
            except Exception:
                pass
    else:
        cache = _config_cache.get("ip_to_hostname")

    return cache.get(ip)