def preview_rule_title(self, search_result: SearchResult) -> str: bi_rule = bi_rule_id_registry[self.rule_id] rule_arguments = replace_macros(self.params.arguments, search_result) mapped_rule_arguments = dict( zip(["$%s$" % x for x in bi_rule.params.arguments], rule_arguments)) return replace_macros(bi_rule.properties.title, mapped_rule_arguments)
def _generate_action_arguments( self, search_results: SearchResults, macros: MacroMapping ) -> ActionArguments: return [ ( replace_macros(self.host_regex, {**macros, **x}), replace_macros(self.service_regex, {**macros, **x}), ) for x in search_results ]
def _generate_action_arguments(self, search_results: SearchResults, macros: MacroMapping) -> ActionArguments: return [ tuple(replace_macros(self.params.arguments, { **macros, **x })) for x in search_results ]
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, macros: MacroMappings) -> List[Dict]: results: List[Dict] = [] new_vars = replace_macros(self.arguments, macros) for argument in new_vars: key = argument["key"] for idx, value in enumerate(argument["values"]): if len(results) <= idx: results.append({}) results[idx]["$%s$" % key] = value return 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: MacroMappings) -> 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) 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[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 _generate_rule_branch(self, nodes: List[ABCBICompiledNode], macros: MacroMappings) -> ABCBICompiledNode: required_hosts = set() for node in nodes: required_hosts.update(node.required_hosts) bi_rule_result = BICompiledRule( self.id, nodes, list(required_hosts), BIRuleProperties(self._properties_config), self.aggregation_function, self.node_visualization, ) bi_rule_result.properties.title = replace_macros(bi_rule_result.properties.title, macros) return bi_rule_result
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]: rule_arguments = replace_macros(self.params.arguments, search_result) return bi_rule_id_registry[self.rule_id].compile( rule_arguments, bi_searcher)
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])]