def parse_hostname_list( self, args: List[str], with_clusters: bool = True, with_foreign_hosts: bool = False) -> List[HostName]: config_cache = config.get_config_cache() if with_foreign_hosts: valid_hosts = config_cache.all_configured_realhosts() else: valid_hosts = config_cache.all_active_realhosts() if with_clusters: valid_hosts = valid_hosts.union(config_cache.all_active_clusters()) hostlist = [] for arg in args: if arg[0] != '@' and arg in valid_hosts: hostlist.append(arg) else: if arg[0] == '@': arg = arg[1:] tagspec = arg.split(',') num_found = 0 for hostname in valid_hosts: if config.hosttags_match_taglist( config_cache.tag_list_of_host(hostname), tagspec): hostlist.append(hostname) num_found += 1 if num_found == 0: raise MKBailOut("Hostname or tag specification '%s' does " "not match any host." % arg) return hostlist
def event_match_hosttags(rule, context): required = rule.get("match_hosttags") if required: tags = context.get("HOSTTAGS", "").split() if not config.hosttags_match_taglist(tags, required): return "The host's tags %s do not match the required tags %s" % ( "|".join(tags), "|".join(required))