#!/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

# example output

factory_settings["filesystem_default_levels"] = FILESYSTEM_DEFAULT_PARAMS


def inventory_nimble_volumes(info):
    for line in info:
        if line[4] == "1":
            yield (line[1], {})


def check_nimble_volumes(item, params, info):
    for line in info:
        if line[1] == item:
            if line[4] == "0":
                yield 3, "Volume is offline!"
                continue
            total = int(line[2])
            free = total - int(line[3])
            yield df_check_filesystem_list(item, params, [(item, total, free, 0)])


check_info["nimble_volumes"] = {
    "inventory_function": inventory_nimble_volumes,
    "check_function": check_nimble_volumes,
    "service_description": "Volume %s",
    "snmp_info": (
        ".1.3.6.1.4.1.37447.1.2.1",
        [
            "2",  # NIMBLE-MIB::volID
            "3",  # NIMBLE-MIB::volName
            "4",  # NIMBLE-MIB::volSizeLow
            "6",  # NIMBLE-MIB::volUsageLow
            "10",  # NIMBLE-MIB::volOnline
        ],
    ),
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(
        ".1.3.6.1.4.1.37447.3.1"
    ),
    "has_perfdata": True,
    "group": "filesystem",
    "default_levels_variable": "filesystem_default_levels",
}
