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

# normal(1):         the environment is good, such as low
#                    temperature.
# warning(2):        the environment is bad, such as temperature
#                    above normal operation range but not too
#                    high.
# critical(3):       the environment is very bad, such as
#                    temperature much higher than normal
#                    operation limit.
# shutdown(4):       the environment is the worst, the system
#                    should be shutdown immediately.
# notPresent(5):     the environmental monitor is not present,
#                    such as temperature sensors do not exist.
# notFunctioning(6): the environmental monitor does not
#                    function properly, such as a temperature
#                    sensor generates a abnormal data like
#                    1000 C.

cisco_temp_perf_envmon_states = {
    1: "normal",
    2: "warning",
    3: "critical",
    4: "shutdown",
    5: "notPresent",
    6: "notFunctioning",
}


def inventory_cisco_temp_perf(info):
    return []


def check_cisco_temp_perf(item, _no_params, info):
    for statustext, _temp, _max_temp, _state, oid_end in info:
        if cisco_sensor_item(statustext, oid_end) == item:
            return 3, "This check is obsolete, please re-inventorize this host"


check_info["cisco_temp_perf"] = {
    "check_function": check_cisco_temp_perf,
    "inventory_function": inventory_cisco_temp_perf,
    "service_description": "Temperature %s",
    "has_perfdata": True,
    "snmp_scan_function": lambda oid: "cisco" in oid(".1.3.6.1.2.1.1.1.0").lower()
    and oid(".1.3.6.1.4.1.9.9.13.1.3.1.3.*") is not None
    and oid(".1.3.6.1.4.1.9.9.91.1.1.1.1.*") is None,
    "snmp_info": (
        ".1.3.6.1.4.1.9.9.13.1.3.1",
        [  # CISCO-SMI
            2,  # ciscoEnvMonTemperatureStatusDescr
            3,  # ciscoEnvMonTemperatureStatusValue
            4,  # ciscoEnvMonTemperatureThreshold
            6,  # ciscoEnvMonTemperatureState
            OID_END,
        ],
    ),
}
