示例#1
0
文件: bi.py 项目: LinuxHaus/checkmk
def _update_bi_rule(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()
    rule_config = params["body"]
    try:
        target_pack = bi_packs.get_pack_mandatory(rule_config["pack_id"])
    except KeyError:
        _bailout_with_message("Unknown bi_pack: %s" % rule_config["pack_id"])

    rule_id = params["rule_id"]
    rule_exists = bool(bi_packs.get_rule(rule_id))
    if rule_exists and not must_exist:
        _bailout_with_message("This rule_id already exists: %s" % rule_id)
    if not rule_exists and must_exist:
        _bailout_with_message("This rule_id does not exist: %s" % rule_id)

    rule_config["id"] = rule_id
    bi_rule = BIRule(rule_config)
    target_pack.add_rule(bi_rule)
    bi_packs.save_config()

    data = {"pack_id": bi_rule.pack_id}
    data.update(bi_rule.schema()().dump(bi_rule))
    return constructors.serve_json(data)
示例#2
0
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)
示例#3
0
    def __init__(self, pack_config: Dict[str, Any]):
        super().__init__()
        self.id = pack_config["id"]
        self.title = pack_config["title"]
        self.comment = pack_config.get("comment", "")
        self.contact_groups = pack_config["contact_groups"]
        self.public = pack_config["public"]

        self.rules = {x["id"]: BIRule(x, self.id) for x in pack_config.get("rules", [])}
        self.aggregations = {
            x["id"]: BIAggregation(x, self.id) for x in pack_config.get("aggregations", [])
        }
示例#4
0
文件: bi.py 项目: hdhoang/checkmk
def put_bi_rule(params):
    """Save BI Rule"""
    bi_packs.load_config()
    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

    bi_rule = BIRule(params["body"])
    target_pack.add_rule(bi_rule)
    bi_packs.save_config()

    data = {"pack_id": bi_rule.pack_id}
    data.update(bi_rule.schema()().dump(bi_rule).data)
    return constructors.serve_json(data)
示例#5
0
文件: bi.py 项目: tboerger/checkmk
def put_bi_rule(params):
    """Save BI Rule"""
    bi_packs = get_cached_bi_packs()
    bi_packs.load_config()
    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"])

    bi_rule = BIRule(params["body"])
    target_pack.add_rule(bi_rule)
    bi_packs.save_config()

    data = {"pack_id": bi_rule.pack_id}
    data.update(bi_rule.schema()().dump(bi_rule))
    return constructors.serve_json(data)