Esempio n. 1
0
def _set_group(
    all_groups: AllGroupSpecs,
    group_type: GroupType,
    name: GroupName,
    extra_info: GroupSpec,
) -> None:
    # Check if this alias is used elsewhere
    alias = extra_info.get("alias")
    if not alias:
        raise MKUserError("alias", "Alias is missing")

    unique, info = is_alias_used(group_type, name, alias)
    if not unique:
        assert info
        raise MKUserError("alias", info)

    all_groups.setdefault(group_type, {})
    all_groups[group_type].setdefault(name, {})
    all_groups[group_type][name] = extra_info
    save_group_information(all_groups)

    if group_type == "contact":
        hooks.call("contactgroups-saved", all_groups)
Esempio n. 2
0
def _save_gui_groups(all_groups: AllGroupSpecs, config_dir: str) -> None:
    multisite_groups: Dict[GroupType, Dict[GroupName, GroupSpec]] = {}

    for group_type, groups in all_groups.items():
        for gid, group in groups.items():
            for attr, value in group.items():
                if attr != "alias":  # Saved in cmk_base
                    multisite_groups.setdefault(group_type, {})
                    multisite_groups[group_type].setdefault(gid, {})
                    multisite_groups[group_type][gid][attr] = value

    store.makedirs(config_dir)
    output = wato_fileheader()
    for what in get_args(GroupType):
        if multisite_groups.get(what):
            output += "multisite_%sgroups = \\\n%s\n\n" % (
                what,
                format_config_value(multisite_groups[what]),
            )
    store.save_text_to_file("%s/groups.mk" % config_dir, output)
Esempio n. 3
0
def _save_cmk_base_groups(all_groups: AllGroupSpecs, config_dir: str) -> None:
    check_mk_groups: Dict[GroupType, Dict[GroupName, str]] = {}
    for group_type, groups in all_groups.items():
        check_mk_groups[group_type] = {}
        for gid, group in groups.items():
            check_mk_groups[group_type][gid] = group["alias"]

    # Save Checkmk world related parts
    store.makedirs(config_dir)
    output = wato_fileheader()
    for group_type in get_args(GroupType):
        if check_mk_groups.get(group_type):
            output += "if type(define_%sgroups) != dict:\n    define_%sgroups = {}\n" % (
                group_type,
                group_type,
            )
            output += "define_%sgroups.update(%s)\n\n" % (
                group_type,
                format_config_value(check_mk_groups[group_type]),
            )
    store.save_text_to_file("%s/groups.mk" % config_dir, output)