#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

# NOTE: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.filerdisks import *  # pylint: disable=wildcard-import,unused-wildcard-import

# Agent output:
# <<<netapp_api_disk:sep(9)>>>

factory_settings["filer_disks_default_levels"] = FILER_DISKS_CHECK_DEFAULT_PARAMETERS


def inventory_netapp_api_disk_summary(info):
    return [(None, {})]


def check_netapp_api_disk_summary(_no_item, params, section):
    # Convert legacy levels
    if "broken_spare_ratio" in params:
        params = {"failed_spare_ratio": params["broken_spare_ratio"]}

    return check_filer_disks(
        [disk for disk in section if disk.get("raid-state") not in ["remote", "partner"]], params
    )


check_info["netapp_api_disk.summary"] = {
    # section is already migrated!
    "check_function": check_netapp_api_disk_summary,
    "inventory_function": inventory_netapp_api_disk_summary,
    "service_description": "NetApp Disks Summary",
    "group": "netapp_disks",
    "has_perfdata": True,
    "default_levels_variable": "filer_disks_default_levels",
}
