#!/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.df import *  # pylint: disable=wildcard-import,unused-wildcard-import

# 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.size_trend import *  # pylint: disable=wildcard-import,unused-wildcard-import

# do need this, the params field can't be None
factory_settings["emc_isilon_ifs"] = {}


def inventory_emc_isilon_ifs(info):
    # this check handles the cluster file system so there is only one
    return [("Cluster", None)]


def check_emc_isilon_ifs(item, params, info):
    ONE_MB = 1024**2
    for total, avail in info:
        size_mb = int(total) // ONE_MB
        avail_mb = int(avail) // ONE_MB
        return df_check_filesystem_list("ifs", params, [("ifs", size_mb, avail_mb, 0)])


check_info["emc_isilon_ifs"] = {
    "check_function": check_emc_isilon_ifs,
    "inventory_function": inventory_emc_isilon_ifs,
    "service_description": "Filesystem %s",
    "group": "filesystem",
    "default_levels_variable": "emc_isilon_ifs",
    "has_perfdata": True,
    "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
            # 2, # ifsUsedBytes
            # 4, # ifsFreeBytes
        ],
    ),
}
