class BIAggregationPackSchema(Schema): id = ReqString(default="", example="bi_pack1") title = ReqString(default="", example="BI Title") comment = String( description= "An optional comment that may be used to explain the purpose of this object.", allow_none=True, example="Rule comment", ) contact_groups = ReqList(fields.String(), default=[], example=["contactgroup_a", "contactgroup_b"]) public = ReqBoolean(default=False) rules = ReqList(fields.Nested(BIRuleSchema()), default=[]) aggregations = ReqList(fields.Nested(BIAggregationSchema()), default=[]) @pre_dump def pre_dumper(self, obj: BIAggregationPack, many=False) -> Dict: # Convert aggregations and rules to list return { "id": obj.id, "title": obj.title, "comment": obj.comment, "contact_groups": obj.contact_groups, "public": obj.public, "rules": obj.get_rules().values(), "aggregations": obj.get_aggregations().values(), }
def get_bi_rule(params): """Get BI Rule""" bi_packs.load_config() bi_rule = bi_packs.get_rule(params["rule_id"]) if bi_rule is None: _bailout_with_message("Unknown bi_rule: %s" % params["rule_id"]) assert bi_rule is not None data = {"pack_id": bi_rule.pack_id} data.update(BIRuleSchema().dump(bi_rule).data) return constructors.serve_json(data)
def get_bi_rule(params): """Show a BI rule""" bi_packs = get_cached_bi_packs() bi_packs.load_config() try: bi_rule = bi_packs.get_rule_mandatory(params["rule_id"]) except KeyError: _bailout_with_message("Unknown bi_rule: %s" % params["rule_id"]) data = {"pack_id": bi_rule.pack_id} data.update(BIRuleSchema().dump(bi_rule)) return constructors.serve_json(data)
def get_bi_rule(params): """Show a BI rule""" user.need_permission("wato.bi_rules") bi_packs = get_cached_bi_packs() bi_packs.load_config() try: bi_rule = bi_packs.get_rule_mandatory(params["rule_id"]) except MKGeneralException: _bailout_with_message("Unknown bi_rule: %s" % params["rule_id"]) data = {"pack_id": bi_rule.pack_id} data.update(BIRuleSchema().dump(bi_rule)) return constructors.serve_json(data)
class BIAggregationPackSchema(Schema): id = ReqString(default="", example="bi_pack1") title = ReqString(default="", example="BI Title") contact_groups = ReqList(fields.String(), default=[], example=["contactgroup_a", "contactgroup_b"]) public = ReqBoolean(default=False) rules = ReqList(fields.Nested(BIRuleSchema()), default=[]) aggregations = ReqList(fields.Nested(BIAggregationSchema()), default=[]) @pre_dump def pre_dumper(self, obj: BIAggregationPack, many=False) -> Dict: # Convert aggregations and rules to list return { "id": obj.id, "title": obj.title, "contact_groups": obj.contact_groups, "public": obj.public, "rules": obj.get_rules().values(), "aggregations": obj.get_aggregations().values(), }