Exemplo n.º 1
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,
        )
Exemplo 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
Exemplo n.º 3
0
    def __init__(self, rule_config: Optional[Dict[str, Any]] = None, pack_id: str = ""):
        super().__init__()
        if rule_config is None:
            rule_config = get_schema_default_config(self.schema())

        self.id = rule_config["id"]
        self.pack_id = pack_id
        self._params = BIParams(rule_config["params"])

        # The raw configuration is kept. It is re-used by the generated BI Branches
        self._properties_config = rule_config["properties"]

        self.aggregation_function = bi_aggregation_function_registry.instantiate(
            rule_config["aggregation_function"])
        self.computation_options = BIRuleComputationOptions(rule_config["computation_options"])
        self.node_visualization = rule_config["node_visualization"]
        self._properties = BIRuleProperties(rule_config["properties"])

        self.nodes = [BINodeGenerator(x) for x in rule_config["nodes"]]
        bi_rule_id_registry.register(self)