예제 #1
0
파일: bi_packs.py 프로젝트: PLUTEX/checkmk
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(),
        }
예제 #2
0
파일: bi.py 프로젝트: hdhoang/checkmk
def get_bi_aggregation(params):
    """Get BI Aggregation"""
    bi_packs.load_config()
    bi_aggregation = bi_packs.get_aggregation(params["aggregation_id"])
    if bi_aggregation is None:
        _bailout_with_message("Unknown bi_aggregation: %s" %
                              params["aggregation_id"])
    assert bi_aggregation is not None

    data = {"pack_id": bi_aggregation.pack_id}
    data.update(BIAggregationSchema().dump(bi_aggregation).data)
    return constructors.serve_json(data)
예제 #3
0
파일: bi.py 프로젝트: mahdi7839/checkmk
def get_bi_aggregation(params):
    """Get BI Aggregation"""
    bi_packs = get_cached_bi_packs()
    bi_packs.load_config()
    try:
        bi_aggregation = bi_packs.get_aggregation_mandatory(params["aggregation_id"])
    except KeyError:
        _bailout_with_message("Unknown bi_aggregation: %s" % params["aggregation_id"])

    data = {"pack_id": bi_aggregation.pack_id}
    data.update(BIAggregationSchema().dump(bi_aggregation))
    return constructors.serve_json(data)
예제 #4
0
파일: bi.py 프로젝트: LinuxHaus/checkmk
def get_bi_aggregation(params):
    """Get a BI aggregation"""
    user.need_permission("wato.bi_rules")
    bi_packs = get_cached_bi_packs()
    bi_packs.load_config()
    try:
        bi_aggregation = bi_packs.get_aggregation_mandatory(params["aggregation_id"])
    except MKGeneralException:
        _bailout_with_message("Unknown bi_aggregation: %s" % params["aggregation_id"])

    data = {"pack_id": bi_aggregation.pack_id}
    data.update(BIAggregationSchema().dump(bi_aggregation))
    return constructors.serve_json(data)
예제 #5
0
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(),
        }