#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk 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 needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.df import *  # pylint: disable=wildcard-import,unused-wildcard-import
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import StringTable
from cmk.base.plugins.agent_based.utils.df import FSBlock

MIBI = 1024**2

factory_settings["filesystem_default_levels"] = FILESYSTEM_DEFAULT_PARAMS


def parse_emc_isilon_ifs(string_table: StringTable) -> FSBlock | None:
    for total, avail in string_table:
        # this check handles the cluster file system so there is only one
        return ("ifs", int(total) // MIBI, int(avail) // MIBI, 0)
    return None


check_info["emc_isilon_ifs"] = {
    "parse_function": parse_emc_isilon_ifs,
    "snmp_scan_function": lambda oid: "isilon" in oid(".1.3.6.1.2.1.1.1.0").lower(),
    "snmp_info": (
        ".1.3.6.1.4.1.12124.1.3",
        [
            1,  # ifsTotalBytes
            3,  # ifsAvailableBytes
        ],
    ),
}


def inventory_emc_isilon_ifs(section: FSBlock):
    return [("Cluster", None)]


def check_emc_isilon_ifs(item, params, section: FSBlock):
    return df_check_filesystem_list("ifs", params, [section])


check_info["emc_isilon_ifs"].update(
    {
        "check_function": check_emc_isilon_ifs,
        "inventory_function": inventory_emc_isilon_ifs,
        "service_description": "Filesystem %s",
        "group": "filesystem",
        "default_levels_variable": "filesystem_default_levels",
        "has_perfdata": True,
    }
)
