#!/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
from cmk.base.check_legacy_includes.size_trend import *  # pylint: disable=wildcard-import,unused-wildcard-import

from cmk.base.check_legacy_includes import dell_compellent


def inventory_dell_compellent_folder(info):
    for line in info:
        if line[1] and float(line[1]) != 0:
            yield (line[0], {})


def check_dell_compellent_folder(item, params, info):
    for number, total, used in info:
        if number == item:
            # sizes delivered in GiB
            total = float(total) * 1024
            free = total - float(used) * 1024
            yield df_check_filesystem_list(item, params, [(item, total, free, 0)])


check_info['dell_compellent_folder'] = {
    'inventory_function': inventory_dell_compellent_folder,
    'check_function': check_dell_compellent_folder,
    'service_description': 'Folder %s',
    'snmp_info': (
        '.1.3.6.1.4.1.674.11000.2000.500.1.2.32.1',
        [
            2,  # DELL-STORAGE-SC-MIB::scDiskFolderSUNbr
            5,  # DELL-STORAGE-SC-MIB::scDiskFolderSUTotalSpace2
            6,  # DELL-STORAGE-SC-MIB::scDiskFolderSUUsedSpace2
        ]),
    'snmp_scan_function': dell_compellent.scan,
    'group': 'filesystem',
}
