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

# .1.3.6.1.4.1.10222.2.1.5.1.0 1 --> ICS-CHASSIS-MIB::icsChassisTemperatureStatus.0
# .1.3.6.1.4.1.10222.2.1.5.2.0 0 --> ICS-CHASSIS-MIB::icsChassisTemperatureWarning.0


def inventory_intel_true_scale_chassis_temp(info):
    if info and info[0][0] != "6":
        return [(None, None)]


def check_intel_true_scale_chassis_temp(_no_item, _no_params, info):
    map_status = {
        "1": (0, "normal"),
        "2": (1, "high"),
        "3": (2, "excessively high"),
        "4": (1, "low"),
        "5": (2, "excessively low"),
        "6": (3, "no sensor"),
        "7": (3, "unknown"),
    }
    map_warn_config = {
        "0": "unspecified",
        "1": "heed warning",
        "2": "ignore warning",
        "3": "no warning feature",
    }

    state, state_readable = map_status[info[0][0]]
    return state, "Status: %s, Warning configuration: %s" % (
        state_readable,
        map_warn_config[info[0][1]],
    )


check_info["intel_true_scale_chassis_temp"] = {
    "inventory_function": inventory_intel_true_scale_chassis_temp,
    "check_function": check_intel_true_scale_chassis_temp,
    "service_description": "Temperature status chassis",
    "snmp_info": (
        ".1.3.6.1.4.1.10222.2.1.5",
        [
            "1",  # ICS-CHASSIS-MIB::icsChassisTemperatureStatus
            "2",  # ICS-CHASSIS-MIB::icsChassisTemperatureWarning
        ],
    ),
    "snmp_scan_function": scan_intel_true_scale,
}
