Пример #1
0
def update_host_tag_group(params):
    """Update a host tag group"""
    # TODO: ident verification mechanism with ParamDict replacement
    body = params['body']
    ident = params['name']
    if is_builtin(ident):
        return problem(
            status=405,
            title="Built-in cannot be modified",
            detail=f"The built-in host tag group {ident} cannot be modified",
        )

    updated_details = {x: body[x] for x in body if x != "repair"}
    tag_group = _retrieve_group(ident)
    group_details = tag_group.get_dict_format()
    group_details.update(updated_details)
    try:
        edit_tag_group(ident,
                       TagGroup(group_details),
                       allow_repair=body['repair'])
    except RepairError:
        return problem(
            401,
            f'Updating this host tag group "{ident}" requires additional authorization',
            'The host tag group you intend to edit is used by other instances. You must authorize Checkmk '
            'to update the relevant instances using the repair parameter')
    updated_tag_group = _retrieve_group(ident)
    return _serve_host_tag_group(updated_tag_group.get_dict_format())
Пример #2
0
def update_host_tag_group(params):
    """Update a host tag group"""
    # TODO: ident verification mechanism with ParamDict replacement
    body = params["body"]
    ident = params["name"]
    if is_builtin(ident):
        return problem(
            status=405,
            title="Built-in cannot be modified",
            detail=f"The built-in host tag group {ident} cannot be modified",
        )

    updated_details = {x: body[x] for x in body if x != "repair"}
    tag_group = _retrieve_group(ident)
    group_details = tag_group.get_dict_format()
    # This is an incremental update of the TaggroupSpec
    group_details.update(updated_details)  # type: ignore[typeddict-item]
    try:
        edit_tag_group(ident,
                       TagGroup.from_config(group_details),
                       allow_repair=body["repair"])
    except RepairError:
        return problem(
            401,
            f'Updating this host tag group "{ident}" requires additional authorization',
            "The host tag group you intend to edit is used by other instances. You must authorize Checkmk "
            "to update the relevant instances using the repair parameter",
        )
    updated_tag_group = _retrieve_group(ident)
    return _serve_host_tag_group(updated_tag_group.get_dict_format())