Esempio n. 1
0
 def _create_node(cls, node_config: Dict[str,
                                         Any]) -> AbstractBICompiledNode:
     if node_config["type"] == BICompiledRule.type():
         return cls.create_tree_from_schema(node_config)
     if node_config["type"] == BICompiledLeaf.type():
         return BICompiledLeaf(**node_config)
     raise NotImplementedError("Unknown node type")
Esempio n. 2
0
    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
Esempio n. 3
0
    def create_tree_from_schema(cls, schema_config: Dict[str, Any]) -> BICompiledRule:
        rule_id = schema_config["id"]
        nodes = [cls._create_node(x) for x in schema_config["nodes"]]
        required_hosts = [(x["site_id"], x["host_name"]) for x in schema_config["required_hosts"]]
        properties = BIRuleProperties(schema_config["properties"])
        aggregation_function = bi_aggregation_function_registry.instantiate(
            schema_config["aggregation_function"])
        node_visualization = schema_config["node_visualization"]

        return BICompiledRule(
            rule_id,
            nodes,
            required_hosts,
            properties,
            aggregation_function,
            node_visualization,
        )
Esempio n. 4
0
    def _use_aggregation_branch(self, compiled_branch: BICompiledRule,
                                bi_aggregation_filter: BIAggregationFilter) -> bool:
        required_elements = compiled_branch.required_elements()
        required_hosts = {x[1] for x in required_elements}
        required_services = {x[2] for x in required_elements if x[2] is not None}
        if bi_aggregation_filter.hosts and len(
                required_hosts.intersection(bi_aggregation_filter.hosts)) == 0:
            return False

        if bi_aggregation_filter.services and len(
                required_services.intersection(bi_aggregation_filter.services)) == 0:
            return False

        if bi_aggregation_filter.aggr_titles and compiled_branch.properties.title not in bi_aggregation_filter.aggr_titles:
            return False

        return True