Ejemplo n.º 1
0
def _update_bi_aggregation(params, must_exist: bool):
    user.need_permission("wato.edit")
    user.need_permission("wato.bi_rules")
    bi_packs = get_cached_bi_packs()
    bi_packs.load_config()
    aggregation_config = params["body"]
    try:
        target_pack = bi_packs.get_pack_mandatory(aggregation_config["pack_id"])
    except MKGeneralException:
        _bailout_with_message("Unknown bi_pack: %s" % aggregation_config["pack_id"])

    aggregation_id = params["aggregation_id"]
    aggregation_exists = bool(bi_packs.get_aggregation(aggregation_id))
    if aggregation_exists and not must_exist:
        _bailout_with_message("This aggregation_id already exists: %s" % aggregation_id)
    if not aggregation_exists and must_exist:
        _bailout_with_message("This aggregation_id does not exist: %s" % aggregation_id)

    aggregation_config["id"] = aggregation_id
    bi_aggregation = BIAggregation(aggregation_config)
    target_pack.add_aggregation(bi_aggregation)
    bi_packs.save_config()

    data = {"pack_id": bi_aggregation.pack_id}
    data.update(bi_aggregation.schema()().dump(bi_aggregation))
    return constructors.serve_json(data)
Ejemplo n.º 2
0
def put_bi_aggregation(params):
    """Save BI Aggregation"""
    bi_packs.load_config()
    bi_aggregation = BIAggregation(params["body"])

    target_pack = bi_packs.get_pack(params["body"]["pack_id"])
    if target_pack is None:
        _bailout_with_message("Unknown bi_pack: %s" %
                              params["body"]["pack_id"])

    assert target_pack is not None
    target_pack.add_aggregation(bi_aggregation)
    bi_packs.save_config()

    data = {"pack_id": bi_aggregation.pack_id}
    data.update(bi_aggregation.schema()().dump(bi_aggregation).data)
    return constructors.serve_json(data)
Ejemplo n.º 3
0
def put_bi_aggregation(params):
    """Save BI Aggregation"""
    bi_packs = get_cached_bi_packs()
    bi_packs.load_config()
    bi_aggregation = BIAggregation(params["body"])

    try:
        target_pack = bi_packs.get_pack_mandatory(params["body"]["pack_id"])
    except KeyError:
        _bailout_with_message("Unknown bi_pack: %s" %
                              params["body"]["pack_id"])

    target_pack.add_aggregation(bi_aggregation)
    bi_packs.save_config()

    data = {"pack_id": bi_aggregation.pack_id}
    data.update(bi_aggregation.schema()().dump(bi_aggregation))
    return constructors.serve_json(data)
Ejemplo n.º 4
0
def test_load_aggregation_integrity(bi_packs_sample_config):
    default_aggregation = bi_packs_sample_config.get_aggregation("default_aggregation")
    assert default_aggregation.id == "default_aggregation"
    assert default_aggregation.groups.names == ["Hosts"]
    assert not default_aggregation.computation_options.disabled
    assert default_aggregation.node.action.rule_id == "host"

    # Generate the schema for the default_aggregation and instantiate a new aggregation from it
    aggregation_schema = BIAggregation.schema()()
    schema_config = aggregation_schema.dump(default_aggregation)
    cloned_aggregation = BIAggregation(schema_config)
    assert cloned_aggregation.id == "default_aggregation"
    assert cloned_aggregation.groups.names == ["Hosts"]
    assert not cloned_aggregation.computation_options.disabled

    action = cloned_aggregation.node.action
    assert isinstance(action, BICallARuleAction)
    assert action.rule_id == "host"