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

factory_settings["huawei_switch_temp_default_levels"] = {
    "levels": (80.0, 90.0),
}


def parse_huawei_switch_temp(info):
    return parse_huawei_physical_entity_values(info)


@get_parsed_item_data
def check_huawei_switch_temp(item, params, item_data):
    try:
        temp = float(item_data.value)
    except TypeError:
        return
    return check_temperature(temp, params, "huawei_switch_temp_%s" % item_data.stack_member)


check_info["huawei_switch_temp"] = {
    "parse_function": parse_huawei_switch_temp,
    "inventory_function": discover(),
    "check_function": check_huawei_switch_temp,
    "service_description": "Temperature %s",
    "snmp_info": huawei_entity_specific_snmp_info(
        (
            ".1.3.6.1.4.1.2011.5.25.31.1.1.1.1",
            [OID_END, "11"],
        )
    ),
    "snmp_scan_function": huawei_switch_scan_function,
    "has_perfdata": True,
    "group": "temperature",
    "default_levels_variable": "huawei_switch_temp_default_levels",
}
