Ejemplo n.º 1
0
def delete_host_tag_group(params):
    """Delete a host tag group"""
    ident = params['name']
    if is_builtin(ident):
        return problem(
            status=405,
            title="Built-in cannot be delete",
            detail=f"The built-in host tag group {ident} cannot be deleted",
        )

    affected = change_host_tags_in_folders(OperationRemoveTagGroup(ident),
                                           TagCleanupMode.CHECK,
                                           watolib.Folder.root_folder())
    if any(affected):
        if not params["repair"]:
            return problem(
                401,
                f'Deleting this host tag group "{ident}" requires additional authorization',
                'The host tag group you intend to delete is used by other instances. You must authorize Checkmk '
                'to update the relevant instances using the repair parameter')
        watolib.host_attributes.undeclare_host_tag_attribute(ident)
        _ = change_host_tags_in_folders(OperationRemoveTagGroup(ident),
                                        TagCleanupMode("delete"),
                                        watolib.Folder.root_folder())

    tag_config = load_tag_config()
    tag_config.remove_tag_group(ident)
    update_tag_config(tag_config)
    return Response(status=204)
Ejemplo n.º 2
0
def delete_host_tag_group(params):
    """Delete a host tag group"""
    ident = params['name']
    allow_repair = params['body'].get("repair", False)
    affected = change_host_tags_in_folders(OperationRemoveTagGroup(ident), TagCleanupMode.CHECK,
                                           watolib.Folder.root_folder())
    if any(affected):
        if not allow_repair:
            return problem(
                401, f'Deleting this host tag group "{ident}" requires additional authorization',
                'The host tag group you intend to delete is used by other instances. You must authorize Checkmk '
                'to update the relevant instances using the repair parameter')
        watolib.host_attributes.undeclare_host_tag_attribute(ident)
        _ = change_host_tags_in_folders(OperationRemoveTagGroup(ident), TagCleanupMode("delete"),
                                        watolib.Folder.root_folder())

    tag_config = load_tag_config()
    tag_config.remove_tag_group(ident)
    update_tag_config(tag_config)
    return Response(status=204)