def __init__(self, aggr_config: Optional[AggrConfigDict] = None, pack_id: str = ""): super().__init__() if aggr_config is None: aggr_config = self.schema()().dump({}) self.id = aggr_config["id"] self.customer = aggr_config.get("customer") self.pack_id = pack_id self.node = BINodeGenerator(aggr_config["node"]) self.groups = BIAggregationGroups(aggr_config["groups"]) self.computation_options = BIAggregationComputationOptions( aggr_config["computation_options"]) self.aggregation_visualization = aggr_config["aggregation_visualization"]
def __init__(self, aggr_config: Optional[Dict[str, Any]] = None, pack_id: str = ""): super().__init__() if aggr_config is None: aggr_config = self.schema()().dump({}).data self.id = aggr_config["id"] # TODO: may be None -> SCOPE_GLOBAL self.customer = aggr_config.get("customer") self.pack_id = pack_id self.node = BINodeGenerator(aggr_config["node"]) self.groups = BIAggregationGroups(aggr_config["groups"]) self.computation_options = BIAggregationComputationOptions( aggr_config["computation_options"]) self.aggregation_visualization = aggr_config[ "aggregation_visualization"]
class BIAggregation: def __init__(self, aggr_config: Optional[AggrConfigDict] = None, pack_id: str = ""): super().__init__() if aggr_config is None: aggr_config = self.schema()().dump({}) self.id = aggr_config["id"] self.customer = aggr_config.get("customer") self.pack_id = pack_id self.node = BINodeGenerator(aggr_config["node"]) self.groups = BIAggregationGroups(aggr_config["groups"]) self.computation_options = BIAggregationComputationOptions( aggr_config["computation_options"]) self.aggregation_visualization = aggr_config["aggregation_visualization"] @classmethod def schema(cls) -> Type["BIAggregationSchema"]: return BIAggregationSchema def clone(self) -> "BIAggregation": aggregation_config = self.schema()().dump(self) return BIAggregation(aggregation_config) def compile(self, bi_searcher: ABCBISearcher) -> BICompiledAggregation: compiled_branches: List[BICompiledRule] = [] if not self.computation_options.disabled: branches = self.node.compile({}, bi_searcher) # Each sub-branch represents one BI Aggregation with an unique name # The postprocessing phase takes care of the "remaining services" action for branch in branches: branch.compile_postprocess(branch, bi_searcher) compiled_branches = self._verify_all_branches_start_with_rule(branches) return BICompiledAggregation( self.id, compiled_branches, self.computation_options, self.aggregation_visualization, self.groups, ) def _verify_all_branches_start_with_rule(self, branches) -> List[BICompiledRule]: new_branches: List[BICompiledRule] = [x for x in branches if isinstance(x, BICompiledRule)] assert len(branches) == len(new_branches) return new_branches @classmethod def create_trees_from_schema(cls, schema_config: Dict[str, Any]) -> BICompiledAggregation: branches = [BIRule.create_tree_from_schema(config) for config in schema_config["branches"]] aggregation_id = schema_config["id"] computation_options = BIAggregationComputationOptions(schema_config["computation_options"]) aggregation_visualization = schema_config["aggregation_visualization"] groups = BIAggregationGroups(schema_config["groups"]) return BICompiledAggregation(aggregation_id, branches, computation_options, aggregation_visualization, groups)
def dummy_bi_rule(): rule_id = "dummy_rule" try: node_schema = BINodeGenerator.schema()().dump({}) node_schema["action"]["host_regex"] = "heute_clone" schema_config = BIRule.schema()().dump({"id": rule_id}) schema_config["nodes"].append(node_schema) yield BIRule(schema_config) finally: bi_rule_id_registry.unregister(rule_id)
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)