def _refer_to_children_with_results( self, search_matches: List[BIHostSearchMatch], bi_searcher: ABCBISearcher, refer_config: dict) -> List[Dict]: referred_tags, referred_host_choice = refer_config all_children: Set[HostName] = set() # Determine pool of childrens for search_match in search_matches: all_children.update(search_match.host.children) # Filter childrens known to bi_searcher children_host_data: List[BIHostData] = [ bi_searcher.hosts[x] for x in all_children if x in bi_searcher.hosts ] # Apply host choice and host tags search matched_hosts, _matched_re_groups = bi_searcher.filter_host_choice( children_host_data, referred_host_choice) matched_hosts = bi_searcher.filter_host_tags(matched_hosts, referred_tags) search_results = [] for host in matched_hosts: # Note: The parameter $1$ does not reflect the first regex match group for the initial host # This information was lost when all children were put into the all_children pool # We can live with it. The option is not used sensibly anywhere anyway :) search_result = { "$1$": host.name, "$HOSTNAME$": host.name, "$HOSTALIAS$": host.alias } search_results.append(search_result) return search_results
def _refer_to_children_with_results( self, search_matches: List[BIHostSearchMatch], bi_searcher: ABCBISearcher, refer_config: dict) -> List[Dict]: referred_tags, referred_host_choice = refer_config all_children: Set[HostName] = set() # Determine pool of childrens for search_match in search_matches: all_children.update(search_match.host.children) # Filter childrens known to bi_searcher children_host_data: List[BIHostData] = [ bi_searcher.hosts[x] for x in all_children if x in bi_searcher.hosts ] # Apply host choice and host tags search matched_hosts, _matched_re_groups = bi_searcher.filter_host_choice( children_host_data, referred_host_choice) matched_hosts = bi_searcher.filter_host_tags(matched_hosts, referred_tags) search_results = [] for host in matched_hosts: search_result = { "$1$": host.name, "$HOSTNAME$": host.name, "$HOSTALIAS$": host.alias } search_results.append(search_result) return search_results
def execute( self, argument: ActionArgument, bi_searcher: ABCBISearcher ) -> List[ABCBICompiledNode]: host_matches, _match_groups = bi_searcher.get_host_name_matches( list(bi_searcher.hosts.values()), argument[0] ) return [BIRemainingResult([x.name for x in host_matches])]
def execute( self, argument: ActionArgument, bi_searcher: ABCBISearcher ) -> List[ABCBICompiledNode]: host_matches, _match_groups = bi_searcher.get_host_name_matches( list(bi_searcher.hosts.values()), argument[0] ) return [BICompiledLeaf(host_name=x.name, site_id=x.site_id) for x in host_matches]
def execute(self, argument: ActionArgument, bi_searcher: ABCBISearcher) -> List[ABCBICompiledNode]: matched_hosts, match_groups = bi_searcher.get_host_name_matches( list(bi_searcher.hosts.values()), argument[0]) host_search_matches = [ BIHostSearchMatch(x, match_groups[x.name]) for x in matched_hosts ] service_matches = bi_searcher.get_service_description_matches( host_search_matches, argument[1]) return [ BICompiledLeaf( site_id=x.host_match.host.site_id, host_name=x.host_match.host.name, service_description=x.service_description, ) for x in service_matches ]
def execute(self, search_result: SearchResult, bi_searcher: ABCBISearcher) -> List[ABCBICompiledNode]: host_re = replace_macros(self.host_regex, search_result) service_re = replace_macros(self.service_regex, search_result) host_matches, _match_groups = bi_searcher.get_host_name_matches( list(bi_searcher.hosts.values()), host_re) action_results: List[ABCBICompiledNode] = [] service_matches = bi_searcher.get_service_description_matches(host_matches, service_re) for service_match in service_matches: action_results.append( BICompiledLeaf( site_id=service_match.host.site_id, host_name=service_match.host.name, service_description=service_match.service_description, )) return action_results
def execute(self, search_result: SearchResult, bi_searcher: ABCBISearcher) -> List[ABCBICompiledNode]: host_re = replace_macros(self.host_regex, search_result) host_matches, _match_groups = bi_searcher.get_host_name_matches( list(bi_searcher.hosts.values()), host_re) action_results: List[ABCBICompiledNode] = [] for host_match in host_matches: action_results.append( BICompiledLeaf(host_name=host_match.name, site_id=host_match.site_id)) return action_results
def execute(self, macros: MacroMapping, bi_searcher: ABCBISearcher) -> List[Dict]: new_conditions = replace_macros(self.conditions, macros) search_matches: List[BIServiceSearchMatch] = bi_searcher.search_services(new_conditions) search_results = [] for search_match in sorted(search_matches, key=lambda x: x.service_description): search_result = { "$1$": search_match.host.name, "$HOSTNAME$": search_match.host.name, "$HOSTALIAS$": search_match.host.alias } for idx, group in enumerate(search_match.match_groups): search_result["$%d$" % (idx + 2)] = group search_results.append(search_result) return search_results
def execute(self, macros: MacroMappings, bi_searcher: ABCBISearcher) -> List[Dict]: new_conditions = replace_macros(self.conditions, macros) search_matches: List[BIHostSearchMatch] = bi_searcher.search_hosts( new_conditions) if self.refer_to == "host": return self._refer_to_host_results(search_matches) if self.refer_to == "child": return self._refer_to_children_results(search_matches, bi_searcher) if self.refer_to == "parent": return self._refer_to_parent_results(search_matches) # TODO: child with, will be done in later commit raise NotImplementedError("Invalid refer to type %r" % self.refer_to)
def execute(self, macros: MacroMapping, bi_searcher: ABCBISearcher) -> List[Dict]: new_conditions = replace_macros(self.conditions, macros) search_matches: List[BIHostSearchMatch] = bi_searcher.search_hosts(new_conditions) if self.refer_to == "host": return self._refer_to_host_results(search_matches) if self.refer_to == "child": return self._refer_to_children_results(search_matches, bi_searcher) if self.refer_to == "parent": return self._refer_to_parent_results(search_matches) if isinstance(self.refer_to, tuple): refer_type, refer_config = self.refer_to if refer_type == "child_with": return self._refer_to_children_with_results(search_matches, bi_searcher, refer_config) raise NotImplementedError("Invalid refer to type %r" % (self.refer_to,))
def execute(self, search_result: SearchResult, bi_searcher: ABCBISearcher) -> List[ABCBICompiledNode]: host_re = replace_macros(self.host_regex, search_result) host_matches, _match_groups = bi_searcher.get_host_name_matches( list(bi_searcher.hosts.values()), host_re) return [BIRemainingResult([x.name for x in host_matches])]